- Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathPlusOne.java
More file actions
Latest commit
28 lines (26 loc) · 569 Bytes
/
Copy pathPlusOne.java
File metadata and controls
28 lines (26 loc) · 569 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
publicclassSolution {
publicint[] plusOne(int[] digits) {
intflag = 1;
inti = 0;
for(i=digits.length-1;i>=0;i--) {
digits[i] = digits[i] + flag;
if(digits[i]>9) {
flag = 1;
digits[i] = 0;
} else {
returndigits;
}
}
//发生进位
if(i==-1&&flag==1) {
int[] newdigits = newint[digits.length+1];
newdigits[0] = 1;
for(i=1;i<=digits.length;i++) {
newdigits[i] = digits[i-1];
}
returnnewdigits;
} else {
returndigits;
}
}
}