class Solution { public: vector<int> plusOne(vector<int> &digits) { int carry = 1; int len = digits.size(); vector<int> res; for (int i=len-1; i>=0; i--) { int cur = carry + digits[i]; carry = cur / 10; cur = cur % 10; res.push_back(cur); } if (carry) { res.push_back(1); } reverse(res.begin(), res.end()); return res; } };
水一发
LeetCode Plus One,布布扣,bubuko.com
原文:http://www.cnblogs.com/lailailai/p/3825263.html