Share my accepted solution, use reverse iterator, 4ms


  • 0
    S
        vector<int>::reverse_iterator rit = digits.rbegin();
        for ( ; rit != digits.rend(); ++rit) {
            if (1+*rit != 10 ) {
                *rit = *rit + 1;
                return digits;
            } else {
                *rit = 0;
            }
        }
        digits.insert(digits.begin(),1);
        return digits;

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.