0
Leetcode Problem 369. Plus One Linked List
369. Plus One Linked List
AI Mock Interview
Leetcode Solutions
Sentinel Head + Textbook Addition
Solution Idea
Algorithm Steps
Code Implementation
Complexity Analysis
Create a new sentinel head node with a value of 0.
Set the sentinel's next pointer to the current head of the list.
Initialize a pointer
notNine
to the sentinel head.
Traverse the list with another pointer
p
. If the current node's value is not nine, update
notNine
to point to this node.
Increment the
notNine
node's value by one.
Set all nodes after
notNine
to zero.
If the sentinel head's value is still zero, return the original head. Otherwise, return the sentinel head.
Reverse, Modify, and Reverse
Ask Question
Programming Language
Purpose:
General Question
Debug My Code
image/screenshot of info
(optional)
[+]
Full Screen
Loading...
Get Answer
Suggested Answer
Answer
Full Screen
Copy Answer Code
Loading...