We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent d8ef1b2 commit f9a4a6dCopy full SHA for f9a4a6d
problems/66.plus-one.md
@@ -101,7 +101,7 @@ result[1] ...... result[result.length - 1] = 0
101
102
## 代码
103
104
-代码支持:Python3,JS, CPP, Go, PHP
+代码支持:Python3,JS, CPP, Go, PHP,Java
105
106
Python3 Code:
107
@@ -195,6 +195,24 @@ class Solution {
195
}
196
```
197
198
+Java code:
199
+
200
+```java
201
+class Solution {
202
+ public int[] plusOne(int[] digits) {
203
+ for (int i = digits.length - 1; i >= 0; i--) {
204
+ digits[i]++;
205
+ digits[i] = digits[i] % 10;
206
+ if (digits[i] != 0) return digits;
207
+ }
208
+ //遇每个数位均为9时手动进位
209
+ digits = new int[digits.length + 1];
210
+ digits[0] = 1;
211
+ return digits;
212
213
+}
214
+```
215
216
**复杂度分析**
217
218
- 时间复杂度:$O(N)$
0 commit comments