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 carray_bit = 0;
digits[digits.size()-1] += 1;
for(int i=digits.size()-1;i>=0;i--) {
if(carray_bit) {
result.push_back(1 + digits[i]);
} else {
result.push_back(digits[i]);
}
if(result[result.size()-1] >= 10) {
result[result.size()-1] %= 10;
carray_bit = 1;
} else {
carray_bit = 0;
}
}
if(carray_bit) {
result.push_back(1);
}
reverse(result.begin(),result.end());
return result;
}
};
转载于:https://www.cnblogs.com/fengjunfeng/archive/2012/10/09/2797768.html