bugfree Icon
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course

Leetcode Problem 369. Plus One Linked List

369. Plus One Linked List

Leetcode Solutions

Sentinel Head + Textbook Addition

  1. Create a new sentinel head node with a value of 0.
  2. Set the sentinel's next pointer to the current head of the list.
  3. Initialize a pointer notNine to the sentinel head.
  4. Traverse the list with another pointer p. If the current node's value is not nine, update notNine to point to this node.
  5. Increment the notNine node's value by one.
  6. Set all nodes after notNine to zero.
  7. If the sentinel head's value is still zero, return the original head. Otherwise, return the sentinel head.
UML Thumbnail

Reverse, Modify, and Reverse

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...