My Blog List

[Leetcode Solution] Reverse Nodes in k-Group

Analysis 

  • Each time reverse one group of nodes
    • Use pre_last denote the last node of previous group
    • Use cur_first denote the first node of current group
    • Each time after reversing, make pre_last->next=cur_first
  • Adding a auxiliary node ahead of the head to avoid the specific situation of the first node

Note

Code


No comments:

Post a Comment

Enter you comment