66. Plus One
题目大意
You are given a large integer represented as an integer array digits
, where each digits[i]
is the i
th digit of the integer. The digits are ordered from most significant to least significant in left-to-right order. The large integer does not contain any leading 0’s.
Increment the large integer by one and return the resulting array of digits.
中文释义
你有一个大整数,表示为整数数组 digits
,其中每个 digits[i]
是该整数的第 i
位数字。数字按从最高位到最低位的左到右顺序排列。该大整数不包含任何前导 0。
将大整数加一,并返回结果数字数组。
示例
示例 1:
输入: digits
= [1,2,3]
输出: [1,2,4]
解释: 数组表示整数 123。
加一得到 123 + 1 = 124。
因此,结果应为 [1,2,4]。
示例 2:
输入: digits
= [4,3,2,1]
输出: [4,3,2,2]
解释: 数组表示整数 4321。
加一得到 4321 + 1 = 4322。
因此,结果应为 [4,3,2,2]。
示例 3:
输入: digits
= [9]
输出: [1,0]
解释: 数组表示整数 9。
加一得到 9 + 1 = 10。
因此,结果应为 [1,0]。
限制条件
1 <= digits.length <= 100
0 <= digits[i] <= 9
<