My Blog List

[Leetcode Solution] Reverse Linked List II

Analysis

  • Idea is quit straightforward. First find the m-th element. Then reverse the linked list started from m to n. Finally return the head of list
  • Note the if m could equal to 1 so we add auxiliary node ahead of the list. Then do the reverse without needing to consider if m==1. Finally delete the first auxiliary node and return the next node

Note

Code


No comments:

Post a Comment

Enter you comment