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

Leetcode Problem 92. Reverse Linked List II

92. Reverse Linked List II

Leetcode Solutions

Iterative Link Reversal

  1. Initialize prev to None and cur to head.
  2. Iterate through the list until cur reaches the leftth node, updating prev and cur.
  3. Mark con (the node before left) and tail (the leftth node).
  4. Continue iterating from left to right, reversing the links by pointing cur.next to prev.
  5. Update prev and cur to the next nodes in the list.
  6. After the sublist is reversed, reconnect the reversed sublist with the rest of the list using con and tail.
  7. If con is not None, point con.next to prev, otherwise set head to prev.
  8. Set tail.next to cur to connect the end of the reversed sublist to the remaining list.
UML Thumbnail

Recursion

Ask Question

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

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...