Given a non-empty array of digits representing a non-negative integer, plus one to the integer.
The digits are stored such that the most significant digit is at the head of the list, and each element in the array contain a single digit.
You may assume the integer does not contain any leading zero, except the number 0 itself.
Example 1: Input: [1,2,3] Output: [1,2,4] Explanation: The array represents the integer 123.
Example 2: Input: [4,3,2,1] Output: [4,3,2,2] Explanation: The array represents the integer 4321.
给定表示非负整数的非空数字数组,加上整数的1。
存储数字使得最高有效数字位于列表的开头,并且数组中的每个元素包含单个数字。
您可以假设整数不包含任何前导零,除了数字0本身。
对于这道题,要求对一个由数组表示每一位的数字,求出其加1后的结果。
其实这个问题还是很有意义的,因为这种方法可以表示一个int范围无法表示的大数。
题目所问的是加一,也可以加其他的数字。
只是加一,就比较简单了,我们在进行相加时,只需要对进位情况进行判断即可。