Posted on

Description

Submission

class Solution {
public:
    vector<int> plusOne(vector<int>& digits) {
        if(digits.empty()) return {1};
        digits.back() += 1;
        if(digits.back() != 10) return digits;
        digits.pop_back();
        vector<int> res = plusOne(digits);
        res.push_back(0);
        return res;
    }
};

Leave a Reply

Your email address will not be published. Required fields are marked *