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.size() == 0) digits.push_back(1);
int carry = 1;
for (vector<int>::iterator it = digits.end() - 1; it >= digits.begin(); --it)
{
int tmp = *it + carry;
*it = tmp % 10;
carry = tmp / 10;
}
if (carry == 1) digits.insert(digits.begin(), 1);
return digits;
}
};