A quite simple solution in Java


  • 0
    Y
     public int[] plusOne(int[] digits) {
        int i=digits.length-1;
        for(;i>0&&digits[i]==9;){
            digits[i--]=0;
        }
        if(i==0&&digits[0]==9){
            int temp[]=new int[digits.length+1];
            temp[0]=1;
            return temp;
        }
        digits[i]+=1;
        return digits;
    }

Log in to reply
 

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