simple java solution


  • 0
    H
    public int[] plusOne(int[] digits) {
            for(int i = digits.length - 1;i >= 0;i--){
                if(digits[i] == 9)
                    digits[i] = 0;
                else{
                    digits[i]++;
                       break;
                }
            }
            int[] newdigits = new int[digits.length + 1];
            newdigits[0] = 1;
            if(digits[0] == 0){
                newdigits[0] = 1;
                return newdigits;
            }
            else
                return digits;
        }
    

Log in to reply
 

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