Skip to content

Commit 0c3285e

Browse files
authored
Create PlusOne.java
1 parent 5fb16c2 commit 0c3285e

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

PlusOne.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
class Solution {
2+
public int[] plusOne(int[] digits) {
3+
int size=digits.length-1;
4+
5+
while(size>=0&&digits[size]==9){
6+
digits[size]=0;
7+
size--;
8+
}
9+
if(size>=0){
10+
digits[size]=digits[size]+1;
11+
return digits;
12+
}
13+
else{
14+
int a[]=new int[digits.length+1];
15+
for(int i=a.length-1;i>0;i--){
16+
a[i]=digits[i-1];
17+
}
18+
a[0]=1;
19+
return a;
20+
}
21+
}
22+
}

0 commit comments

Comments
 (0)