Problem:
Given a number represented as an array of digits, plus one to the number.
class Solution {
public:
vector<int> plusOne(vector<int> &digits) {
// Start typing your C/C++ solution below
// DO NOT write int main() function
vector<int> result;
int nSize = digits.size();
int carry = 1;
for (int i = nSize - 1; i >= 0; --i)
{
int tmp = digits[i] + carry;
digits[i] = tmp % 10;
carry = tmp / 10;
}
if (carry)
result.push_back(1);
for (int i = 0; i < nSize; ++i)
result.push_back(digits[i]);
return result;
}
};