/*本题是一道模拟题,模拟数字的加法即可。
方法参考自: https://github.com/soulmachine/leetcode
*/
class Solution {
public:
vector<int> plusOne(vector<int> &digits) {
int carry(1);
for(vector<int>::reverse_iterator it = digits.rbegin(); it != digits.rend(); ++it){
*it += carry;
carry = *it / 10;
*it %= 10;
}
if(carry > 0) digits.insert(digits.begin(), 1);
return digits;
}
};
08-18