Add to Array-Form of Integer

Easy Topics Company Tags

The array num contains the decimal digits of a non-negative integer, from most significant to least significant. It has no leading zero unless the entire number is zero. Add the positive integer k and return the sum as an array of decimal digits in the same order. The input number may have thousands of digits.

Example 1:

Input: num = [9,9]
k = 1

Output: [1,0,0]

Explanation: The digits represent 99. Adding 1 gives 100, so the returned digits are [1,0,0].

Example 2:

Input: num = [0]
k = 37

Output: [3,7]

Explanation: The input represents zero. Adding 37 gives the digits [3,7].

Example 3:

Input: num = [1,0,0]
k = 25

Output: [1,2,5]

Explanation: The input represents 100. Adding 25 gives 125, represented by [1,2,5].

Constraints:

  • 1 <= num.length <= 10000
  • 0 <= num[i] <= 9
  • num has no leading zeros unless it is [0].
  • 1 <= k <= 10000


Topics

Company Tags

Please upgrade to NeetCode Pro to view company tags.