preface

Recently, some friends asked me why I haven’t updated my article. I have been scanning LeetCode for nearly two months now and then in my spare time, and I have accumulated a lot of questions. Therefore, I plan to classify the hundreds of questions I have done recently and summarize them. The code for all topics is available at github.com/halfrost/Le… Each problem has test cases and test code.

Linked List of Tips:

  • Cleverly construct virtual headers. Can make traversal processing logic more uniform.
  • Be flexible with recursion. Construct recursion condition, use recursion can clever solution problem. Note, however, that you should not use recursion for some problems, because too deep recursion can cause timeouts and stack overflows.
  • List interval reverse order. The 92th.
  • Linked lists look for intermediate nodes. The 876th. The linked list looks for the NTH to last node. 19 items. It only takes one walk to get the answer.
  • Merge K ordered linked lists. Problem 21. Problem 23.
  • Linked list categorization. Problem 86. Problem 328.
  • Linked list sorting requires O(n * log n) time complexity and O(1) space complexity. There’s only one way to do it, merge sort, top down merge. The 148th.
  • Determine whether the linked list has a ring, if there is a ring, output the index of the intersection of the ring; Check if two lists have intersections, if so, output the intersections. Problem 141. Problem 142. Problem 160.
Title Solution Difficulty Time Space collection
2. Add Two Numbers Go Medium O(n) O(1)
19. Remove Nth Node From End of List Go Medium O(n) O(1)
21. Merge Two Sorted Lists Go Easy O(log n) O(1)
23. Merge k Sorted Lists Go Hard O(log n) O(1) ❤ ️
24. Swap Nodes in Pairs Go Medium O(n) O(1)
25. Reverse Nodes in k-Group Go Hard O(log n) O(1) ❤ ️
61. Rotate List Go Medium O(n) O(1)
82. Remove Duplicates from Sorted List II Go Medium O(n) O(1)
83. Remove Duplicates from Sorted List Go Easy O(n) O(1)
86. Partition List Go Medium O(n) O(1) ❤ ️
92. Reverse Linked List II Go Medium O(n) O(1) ❤ ️
109. Convert Sorted List to Binary Search Tree Go Medium O(log n) O(n)
141. Linked List Cycle Go Easy O(n) O(1) ❤ ️
142. Linked List Cycle II Go Medium O(n) O(1) ❤ ️
143. Reorder List Go Medium O(n) O(1) ❤ ️
147. Insertion Sort List Go Medium O(n) O(1)
148. Sort List Go Medium O(log n) O(n) ❤ ️
160. Intersection of Two Linked Lists Go Easy O(n) O(1) ❤ ️
203. Remove Linked List Elements Go Easy O(n) O(1)
206. Reverse Linked List Go Easy O(n) O(1)
234. Palindrome Linked List Go Easy O(n) O(1)
237. Delete Node in a Linked List Go Easy O(n) O(1)
328. Odd Even Linked List Go Medium O(n) O(1)
445. Add Two Numbers II Go Medium O(n) O(n)
725. Split Linked List in Parts Go Medium O(n) O(1)
817. Linked List Components Go Medium O(n) O(1)
707. Design Linked List Go Easy O(n) O(1)
876. Middle of the Linked List Go Easy O(n) O(1) ❤ ️
1019. Next Greater Node In Linked List Go Medium O(n) O(1)