Javascript solution to handle more that 16 digits input


  • 0
    K
    /**
     * @param {number[]} digits
     * @return {number[]}
     */
    var plusOne = function(digits) {
        digits=digits.reverse();
        var addnext=1;
    for(var i=0;i<digits.length;i++){
        if(digits[i]===9 && addnext===1){
            digits[i]=0;
        }
        else{
            digits[i]=digits[i]+addnext;
            addnext=0;
        }
    }
    if(addnext==1){
        digits.push(addnext)
    }
        
        return digits.reverse();
        
    };
    

Log in to reply
 

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