#989

Add to Array-Form of Integer

pupil · 465 · lc easy +26 · verified · 45.4% accepted · 3,681 likes · top 29%

Description

The array-form of a non-negative integer lists its decimal digits from left to right (e.g., 1321[1,3,2,1]). Given the array-form num and a non-negative integer k, return the array-form of their sum num + k.

Example 1:

Input: num = [1,2,0,0], k = 34
Output: [1,2,3,4]
Explanation: 1200 + 34 = 1234

Example 2:

Input: num = [2,7,4], k = 181
Output: [4,5,5]
Explanation: 274 + 181 = 455

Example 3:

Input: num = [2,1,5], k = 806
Output: [1,0,2,1]
Explanation: 215 + 806 = 1021

Code

1
2
3