Given a non-negative number represented as an array of digits, plus one to the number.
The digits are stored such that the most significant digit is at the head of the list.
思路:模拟整数的加法,这个比较简单
class Solution {
public:
vector<int> plusOne(vector<int>& digits) {
if(digits.empty()) return digits;
int next = 1;
int tmp;
for (int i = digits.size() - 1; i >= 0; i--){
tmp = digits[i] + next;
next = tmp / 10;
digits[i] = tmp % 10;
}
if (next) digits.insert(digits.begin(), next);
return digits;
}
};