My Simple JavaScript Solution, beats 100%


  • 0
    S
    plusOne(d) {
        for (let i=d.length-1; i >= 0; i--) {
            if (d[i] == 9) {
                if (i === 0) { 
                    d.unshift(1);
                    d[i + 1] = 0;
                    break; 
                };
                d[i] = 0;
    
            } else {
                d[i] += 1;
                break;
            }
        }
        return d;
    }
    

Log in to reply
 

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