ACCEPT JAVA solutions


  • 0
    H
    public int[] plusOne(int[] digits) {
        int index = digits.length-1;
        while(digits[index]==9&&index>0){
            digits[index]=0;
            index--;
        }
        if(digits[index]==9){
            int[] d2 = new int[digits.length+1];
            d2[0]=1;
            return d2;
        }else{
            digits[index]= digits[index]+1;
            return digits;
        }
    }
    

    but this ver will not work with [] (empty array)as input


Log in to reply
 

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