标签:
Given a non-negative number represented as an array of digits, plus one to the number.
The digits are stored such that the most significant digit is at the head of the list.
题意:大数加法。class Solution { public: vector<int> plusOne(vector<int> &digits) { vector<int> ans(digits); reverse(ans.begin(),ans.end()); int one = 1; for (int i = 0; i < ans.size(); i++) { ans[i] += one; one = ans[i] / 10; ans[i] %= 10; } if (one != 0) ans.push_back(one); reverse(ans.begin(), ans.end()); return ans; } };
标签:
原文地址:http://blog.csdn.net/u011345136/article/details/44751107