Plus One javascript 85%


  • 0
    A
    /**
     * @param {number[]} digits
     * @return {number[]}
     */
    var plusOne = function(digits) {
        var digitsLen = digits.length;
    
        for (var i = digitsLen-1; i >= 0; i-- ) {
        	if (digits[i] !== 9) {
        		digits[i] = ++digits[i];
        		break;
        	} else {
        		digits[i] = 0;
        		if (!i) {
        			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.