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.
解题报告:非常简单的题,相当于进行进位加减。[6,5,8,9]输出[6,5,9,0],[9,9]输出[1,0,0]
class Solution {
public:
vector<int> plusOne(vector<int> &digits) {
vector<int> answers;
int plusSignal = 1;
for(int i = digits.size() -1 ; i >= 0; i--)
{
int Num = digits[i] + plusSignal;
answers.insert(answers.begin(),Num%10);
plusSignal = Num / 10;
}
if(plusSignal == 1)
answers.insert(answers.begin(),1);
return answers;
}
};