Java solution (0 ms)


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

Log in to reply
 

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