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

Commit 981a7fa

Browse files
author
Dream
committed
[update] one solution
1 parent fa10d46 commit 981a7fa

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
|993|[Cousins in Binary Tree](https://leetcode.com/problems/cousins-in-binary-tree/) | [java](./algorithm/cousinsInBinaryTree/solution.java) |Easy|
2020
|991|[Broken Calculator](https://leetcode.com/problems/broken-calculator/) | |Medium|
2121
|990|[Satisfiability of Equality Equations](https://leetcode.com/problems/satisfiability-of-equality-equations/) | |Medium|
22-
|989|[Add to Array-Form of Integer](https://leetcode.com/problems/add-to-array-form-of-integer/) | |Easy|
22+
|989|[Add to Array-Form of Integer](https://leetcode.com/problems/add-to-array-form-of-integer/) | [java_dream](./algorithms/addToArrayFormOfInteger/AddToArrayFormOfInteger.java)|Easy|
2323
|988|[Smallest String Starting From Leaf](https://leetcode.com/problems/smallest-string-starting-from-leaf/) | |Medium|
2424
|987|[Vertical Order Traversal of a Binary Tree](https://leetcode.com/problems/vertical-order-traversal-of-a-binary-tree/) | |Medium|
2525
|986|[Interval List Intersections](https://leetcode.com/problems/interval-list-intersections/) | |Medium|
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import java.util.LinkedList;
2+
import java.util.List;
3+
4+
/**
5+
* @author Dream
6+
*/
7+
public class AddToArrayFormOfInteger {
8+
public List<Integer> addToArrayForm(int[] num, int k) {
9+
int len = num.length;
10+
int lastNum = k;
11+
LinkedList<Integer> list = new LinkedList<>();
12+
int i = len - 1;
13+
while (i >= 0 || lastNum > 0) {
14+
if (i >= 0) {
15+
lastNum += num[i];
16+
}
17+
list.addFirst(lastNum % 10);
18+
lastNum /= 10;
19+
i--;
20+
}
21+
return list;
22+
}
23+
}

0 commit comments

Comments
 (0)