public int[] plusOne(int[] digits) {
        int[] result = new int[digits.length];
        System.arraycopy(digits, 0, result, 0, digits.length);
        
        if (digits == null || digits.length == 0) {
            return digits;
        }
        
        for (int i = result.length-1; i >= 0; i--) {
            if (result[i] < 9) {
                result[i]++;
                break;
            }
            else {
                result[i] = 0;
            }
        }
        if (result[0] == 0) {
            int[] newresult = new int[digits.length + 1];
            System.arraycopy(result, 1, newresult, 0, digits.length);
            newresult[0] = 1;
            result = newresult;
        }
        return result;
    }