-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlus One
More file actions
27 lines (26 loc) · 691 Bytes
/
Plus One
File metadata and controls
27 lines (26 loc) · 691 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
class Solution {
static ArrayList<Integer> increment(ArrayList<Integer> arr , int N) {
// code here
ArrayList<Integer> result=new ArrayList<>();
if(arr.get(N-1)<9)
arr.set(N-1,arr.get(N-1)+1);
else{
for(int i=N-1;i>=0;i--){
int num=arr.get(i);
if(num==9){
arr.set(i,0);}
else {
arr.set(i,num+1);
break;
}
}
}
if(arr.get(0)==0){
result.add(1);
for(int i=1;i<=N;i++)
result.add(0);
return result;
}
return arr;
}
};