66. Plus One 發表於 2023-02-13 | 分類於 leetcode problemsolution1234567891011121314151617181920class Solution {public: vector<int> plusOne(vector<int>& digits) { int carry = 0, n= digits.size()-1; while(n>-1){ if(digits[n] == 9){ digits[n]= 0; n--; } else{ digits[n]++; break; } } if(digits[0] == 0) digits.insert(digits.begin() ,1); return digits; }}; analysis time complexity O(n) space complexity O(1)