public int[] plusOne(int[] digits) {
        int len = digits.length;
        if(len == 0) return digits;
        boolean allNine = true;
        for(int digit : digits){
             if(digit != 9) allNine = false;
        }
        if(allNine){
            int[] result = new int[len + 1];
            result[0] = 1;
            return result;
        }else{
            int i = len - 1;
            while(i >= 0){
                if(digits[i] + 1 < 10){
                    digits[i] += 1;
                    return digits;
                }else{
                    digits[i] = 0;
                    i--;
                }
            }
            return digits;
        }
    }