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.
注意点:1. insert的运用 2. 前缀为0的情况
class Solution {
public:
vector<int> plusOne(vector<int>& digits) {
int i = digits.size() - 1;
for(; i>=0; i--)
{
if(digits[i]!=9)
{
digits[i]++;
break;
}
digits[i] = 0;
}
if(digits[0]==0 && i<0) //前缀为0用i<0判断
{
digits.insert(digits.begin(),1);
}
return digits;
}
};