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> answer;
int c = 1;
for (int i = digits.size() - 1; i >= 0; i--) {
c += digits[i];
answer.insert(answer.begin(), c % 10);
c = c / 10;
}
if (c > 0) {
answer.insert(answer.begin(), c);
}
return answer;
}
};