Plus One Linked List - Problem
Given a non-negative integer represented as a linked list of digits, plus one to the integer.
The digits are stored such that the most significant digit is at the head of the list.
For example, the number 123 is stored as 1 → 2 → 3.
Goal: Add 1 to this number and return the modified linked list.
Input & Output
Example 1 — Basic Addition
$
Input:
head = [1,2,3]
›
Output:
[1,2,4]
💡 Note:
The number is 123, plus one gives 124, represented as 1→2→4
Example 2 — Carry Propagation
$
Input:
head = [4,3,2,1]
›
Output:
[4,3,2,2]
💡 Note:
The number is 4321, plus one gives 4322, represented as 4→3→2→2
Example 3 — All Nines
$
Input:
head = [9,9,9]
›
Output:
[1,0,0,0]
💡 Note:
The number is 999, plus one gives 1000, requiring a new head node: 1→0→0→0
Constraints
- 1 ≤ Number of nodes ≤ 100
- 0 ≤ Node.val ≤ 9
- The number does not have leading zeros, except the number 0 itself
Visualization
Tap to expand
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code