题解 | #给数组加一#
给数组加一
https://www.nowcoder.com/practice/e20d6e18e75941b6a5b7b33ffa7b8d4d
class Solution { public: vector<int> plusOne(vector<int>& nums) { int i = nums.size()-1; nums[i]++; while(nums[i]==10 && i>0) { nums[i]=0; i--; nums[i]++; } if(nums[i]==10) { nums[i]=0; nums.insert(nums.begin(), 1); } return nums; } };