Loading...
You are given a non-negative integer as an array digits, most significant digit first, with no leading zeros. Add 1 to the number.
Return the resulting digit array in the same format.
Input: digits = [1,2,3]
Output: [1,2,4]
Explanation: The array encodes 123; 123 + 1 = 124.
Input: digits = [4,3,2,1]
Output: [4,3,2,2]
Explanation: The array encodes 4321; 4321 + 1 = 4322.
Input: digits = [9]
Output: [1,0]
Explanation: 9 + 1 = 10, which needs one more digit than the input.
digits.length ≤100digits[i] ≤9digits contains no leading zeros.Click "Run" to test with sample cases or "Submit" to run all tests.