/66. Plus One

66. Plus One

Easy
Arrays49.7% acceptance

Given an array of integers digit_array representing a non-negative integer, where each element digit_array[i] is a digit and the digits are ordered from most significant to least significant, increment the integer by one and return the resulting array of digits. The input array does not contain leading zeros.

Example 1

Input: [2, 5, 9]

Output: [2, 6, 0]

Explanation: 259 + 1 = 260

Example 2

Input: [7, 9, 9]

Output: [8, 0, 0]

Explanation: 799 + 1 = 800

Example 3

Input: [0]

Output: [1]

Explanation: 0 + 1 = 1

Example 4

Input: [1, 0, 0, 0]

Output: [1, 0, 0, 1]

Explanation: 1000 + 1 = 1001

Constraints

  • 1 <= len(digit_array) <= 100
  • 0 <= digit_array[i] <= 9
  • digit_array[0] != 0 or len(digit_array) == 1
Python (current runtime)

Case 1

Input: [3, 4, 5]

Expected: [3, 4, 6]

Case 2

Input: [9, 9, 9]

Expected: [1, 0, 0, 0]

Case 3

Input: [5, 0, 0]

Expected: [5, 0, 1]

Case 4

Input: [8]

Expected: [9]

Case 5

Input: [1, 2, 9]

Expected: [1, 3, 0]