Add Number to Array-Form Integer
EasyP2Coding
The array form of a non-negative integer is the array of its digits from most significant to least. For example 1321 is [1,3,2,1].
Given num, the array form of a number, and an integer k, return the array form of their sum. The result has no leading zeros (except for the number 0, which is [0]).
Example 1
- Input
- num = [1,2,3], k = 12
- Output
- [1,3,5]
- Why
- 123 + 12 = 135.
Example 2
- Input
- num = [9,9,9], k = 1
- Output
- [1,0,0,0]
Example 3
- Input
- num = [0], k = 0
- Output
- [0]
Constraints
- 1 <= num.length <= 10^4
- 0 <= num[i] <= 9
- num has no leading zeros except for the number 0 itself
- 0 <= k <= 10^4
Hints
Give it a real attempt first. Run shows which examples fail.
Saved automatically
Run checks the 3 visible tests, Submit all 10. ⌘Enter runs, ⌘⇧Enter submits.