Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit c4df790

Browse files
authored
Create Solution.java
1 parent e25318a commit c4df790

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
class Solution {
2+
public List<Integer> addToArrayForm(int[] A, int K) {
3+
for (int i = A.length - 1; i >= 0 && K != 0; --i) {
4+
K += A[i];
5+
A[i] = K % 10;
6+
K /= 10;
7+
}
8+
List<Integer> res = new ArrayList<>();
9+
while (K != 0) {
10+
res.add(K % 10);
11+
K /= 10;
12+
}
13+
Collections.reverse(res);
14+
for (int a : A) {
15+
res.add(a);
16+
}
17+
return res;
18+
}
19+
}

0 commit comments

Comments
 (0)