Java | TC: O(N) | SC: O(1) | Optimized Math Addition simulation
java\n/**\n * Simulate Math Addition\n *\n * Time Complexity: O(N)\n *\n * Space Complexity: O(1) --> Excluding the result space\n *\n * N = Length of input dig
```java\n/**\n * Simulate Math Addition\n *\n * Time Complexity: O(N)\n *\n * Space Complexity: O(1) --> Excluding the result space\n *\n * N = Length of input digits array.\n */\nclass Solution {\n    public int[] plusOne(int[] digits) {\n        if (digits == null) {\n            throw new IllegalArgumentException("Input array is null");\n        }\n\n        int len = digits.length;\n        if (len == 0) {\n            return new int[] { 1 };\n        }\n\n        for (int i = len - 1; i >= 0; i--) {\n            if (digits[i] != 9) {\n                digits[i]++;\n                return digits;\n            }\n            digits[i] = 0;\n        }\n\n        digits = new int[len + 1];\n        digits[0] = 1;\n        return digits;\n    }\n}\n```
['Array', 'Math', 'Java']