My JavaScript Solution


  • 0
    B
    var plusOne = function(digits) {
        var s = 0;
        digits[digits.length - 1]++;
        for(var i = digits.length - 1; i >= 0; i--) {
            digits[i]+=s;
            if(digits[i] >= 10) {
                s = 1;
                digits[i] = digits[i] - 10;
            } else {
                s = 0;
            }
        }
        if(s === 1) digits.unshift(1);
        return digits;
    };
    

Log in to reply
 

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