Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit26c7e48

Browse files
Jian GUfishercoder1534
Jian GU
authored andcommitted
Update _66.java (fishercoder1534#37)
1 parent2ae6175 commit26c7e48

File tree

1 file changed

+17
-28
lines changed
  • src/main/java/com/fishercoder/solutions

1 file changed

+17
-28
lines changed

‎src/main/java/com/fishercoder/solutions/_66.java

Lines changed: 17 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -10,35 +10,24 @@ public class _66 {
1010

1111
publicstaticclassSolution1 {
1212
publicint[]plusOne(int[]digits) {
13-
booleancarry =false;
14-
intlen =digits.length;
15-
int[]temp =digits;
16-
//process the last digit at first, to get carry value
17-
if (digits[len -1] +1 ==10) {
18-
carry =true;
19-
temp[len -1] =0;
20-
}else {
21-
temp[len -1] +=1;
22-
returntemp;
23-
}
24-
25-
//start from the second last element
26-
for (inti =len -2;i >=0;i--) {
27-
if (carry &&temp[i] +1 ==10) {
28-
temp[i] =0;
29-
carry =true;
30-
}elseif (carry) {
31-
temp[i] +=1;
32-
carry =false;
13+
intlen =digits.length;
14+
int[]temp =digits;
15+
16+
for (inti =len -1;i >=0;i--) {
17+
if (temp[i] +1 ==10) {
18+
temp[i] =0;
19+
}else {
20+
temp[i] +=1;
21+
returntemp;
22+
}
23+
}
24+
if (temp[0] ==0) {
25+
int[]res =newint[len +1];
26+
res[0] =1;//all the rest of the numbers should all be zeroes, so we don't need to copy from the original array
27+
returnres;
28+
}else {
29+
returntemp;
3330
}
34-
}
35-
if (carry &&temp[0] ==0) {
36-
int[]res =newint[len +1];
37-
res[0] =1;
38-
//all the rest of the numbers should all be zeroes, so we don't need to copy from the original array
39-
returnres;
40-
}
41-
returntemp;
4231
}
4332
}
4433
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp