题目
Given a non-negative integer represented as a non-empty array of digits, plus one to the integer.
You may assume the integer do not contain any leading zero, except the number 0 itself.
The digits are stored such that the most significant digit is at the head of the list.
思路
弄个临时变量记进位,从第n-1
位按照加法开始依次加就好了。
代码
1 | //C++ Solution |
然后Discuss看到了个比较吊的
1 | //C++ Solution |