clean code
记得以前写过这题,写的乱七八糟,分析来分析去。
后悔应该早点写代码,leetcode大一就该刷了。
https://leetcode.cn/problems/plus-one/submissions/
class Solution {
public:vector<int> plusOne(vector<int>& digits) {bool carry = true;vector<int>ans;for (int i = digits.size() - 1; i >= 0; --i) {if (carry) {int tmp = digits[i] + 1;if (tmp == 10) {ans.push_back(0);}else {ans.push_back(tmp);carry = false;}}else {ans.push_back(digits[i]);}}if (carry)ans.push_back(1);reverse(ans.begin(), ans.end());return ans;}
};