Untitled

mail@pastecode.io avatar
unknown
c_cpp
2 years ago
300 B
1
Indexable
Never
class Solution {
public int[] plusOne(int[] d) {
int flag = 0;
for(int i = d.length-1;i>-1;i--){
if(d[i]!=9){d[i] += 1;
flag=1;
break;
}
else{d[i] = 0;}
}
if(flag == 0){
int a[] = new int[d.length+1];
a[0] = 1;
for(int i=1;i<a.length;i++){
a[i] = d[i-1];}
return a;
}
return d;
}
}