0ms java Solution 1 pass


  • 3
    C
    public int[] plusOne(int[] digits) {
        if(digits==null || digits.length==0)
            return digits;
        for(int i=digits.length-1; i>=0; i--){
            if(digits[i]!=9){
                digits[i]++;
                break;
            }else if(i==0){
                int[] result = new int[digits.length+1];
                result[0] = 1;
                return result;
            }else
                digits[i]=0;
        }
        return digits;
    }

  • 0
    K

    public int[] PlusOne(int [] digits)
    {
    int len=digits.length;
    for(int i=len-1;i>=0;i++)
    {
    if(digits[i]!=9)
    {
    digits[i]++;
    return digits;
    }
    else
    digits[i]=0;
    }
    int [] tmp=new int[len+1];
    tmp[0]=1;
    return tmp;
    }


  • 0
    C

    Would appreciate if you can format your code.
    Thanks


Log in to reply
 

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