Back to January Back to Year 2026
EASY 01 Jan 2026 View on LeetCode

66. Plus One

</> Solution

/**
 * Problem: LeetCode 66 - Plus One
 * Difficulty: Easy
 * Language: Java
 * Author: CodeByTushu
 */
class Solution {
    public int[] plusOne(int[] digits) {
        int n = digits.length;
        // Traverse digits from right to left
        for (int i = n - 1; i >= 0; i--) {
            if (digits[i] < 9) {
                digits[i]++;
                return digits;
            }
            digits[i] = 0;
        }
        // If all digits were 9 (e.g. 99 -> 100)
        int[] result = new int[n + 1];
        result[0] = 1;
        return result;
    }
}

TIME COMPLEXITY

O(N)

SPACE COMPLEXITY

O(1)

TOPICS

Array Math