Back to Leetcode Go

2.04 ✅ Linked List

website/content.en/ChapterTwo/Linked_List.md

1.7.977.3 KB
Original Source

Linked List

  • Cleverly construct a dummy head node. This can make the traversal and processing logic more uniform.
  • Use recursion flexibly. By constructing recursive conditions, recursion can be used to solve problems cleverly. However, note that recursion cannot be used for some problems, because excessive recursion depth can cause timeouts and stack overflow.
  • Reverse a linked list interval. Problem 92.
  • Find the middle node of a linked list. Problem 876. Find the nth node from the end of a linked list. Problem 19. The answer can be obtained with just one traversal.
  • Merge K sorted linked lists. Problems 21 and 23.
  • Classify linked lists. Problems 86 and 328.
  • Sort a linked list, requiring time complexity O(n * log n) and space complexity O(1). There is only one approach: merge sort, top-down merging. Problem 148.
  • Determine whether a linked list has a cycle; if it has a cycle, output the index of the intersection point of the cycle; determine whether 2 linked lists have an intersection point; if there is an intersection point, output the intersection point. Problems 141, 142, and 160.
No.TitleSolutionDifficultyTimeComplexitySpaceComplexityFavoriteAcceptance
0002Add Two Numbers[Go]({{< relref "/ChapterFour/0001~0099/0002.Add-Two-Numbers.md" >}})MediumO(n)O(1)40.4%
0019Remove Nth Node From End of List[Go]({{< relref "/ChapterFour/0001~0099/0019.Remove-Nth-Node-From-End-of-List.md" >}})MediumO(n)O(1)41.1%
0021Merge Two Sorted Lists[Go]({{< relref "/ChapterFour/0001~0099/0021.Merge-Two-Sorted-Lists.md" >}})EasyO(log n)O(1)62.5%
0023Merge k Sorted Lists[Go]({{< relref "/ChapterFour/0001~0099/0023.Merge-k-Sorted-Lists.md" >}})HardO(log n)O(1)❤️49.8%
0024Swap Nodes in Pairs[Go]({{< relref "/ChapterFour/0001~0099/0024.Swap-Nodes-in-Pairs.md" >}})MediumO(n)O(1)61.3%
0025Reverse Nodes in k-Group[Go]({{< relref "/ChapterFour/0001~0099/0025.Reverse-Nodes-in-k-Group.md" >}})HardO(log n)O(1)❤️54.7%
0061Rotate List[Go]({{< relref "/ChapterFour/0001~0099/0061.Rotate-List.md" >}})MediumO(n)O(1)36.1%
0082Remove Duplicates from Sorted List II[Go]({{< relref "/ChapterFour/0001~0099/0082.Remove-Duplicates-from-Sorted-List-II.md" >}})MediumO(n)O(1)45.9%
0083Remove Duplicates from Sorted List[Go]({{< relref "/ChapterFour/0001~0099/0083.Remove-Duplicates-from-Sorted-List.md" >}})EasyO(n)O(1)50.6%
0086Partition List[Go]({{< relref "/ChapterFour/0001~0099/0086.Partition-List.md" >}})MediumO(n)O(1)❤️52.0%
0092Reverse Linked List II[Go]({{< relref "/ChapterFour/0001~0099/0092.Reverse-Linked-List-II.md" >}})MediumO(n)O(1)❤️45.4%
0109Convert Sorted List to Binary Search Tree[Go]({{< relref "/ChapterFour/0100~0199/0109.Convert-Sorted-List-to-Binary-Search-Tree.md" >}})MediumO(log n)O(n)60.2%
0114Flatten Binary Tree to Linked List[Go]({{< relref "/ChapterFour/0100~0199/0114.Flatten-Binary-Tree-to-Linked-List.md" >}})Medium61.8%
0116Populating Next Right Pointers in Each Node[Go]({{< relref "/ChapterFour/0100~0199/0116.Populating-Next-Right-Pointers-in-Each-Node.md" >}})Medium60.4%
0138Copy List with Random Pointer[Go]({{< relref "/ChapterFour/0100~0199/0138.Copy-List-with-Random-Pointer.md" >}})Medium51.4%
0141Linked List Cycle[Go]({{< relref "/ChapterFour/0100~0199/0141.Linked-List-Cycle.md" >}})EasyO(n)O(1)❤️47.5%
0142Linked List Cycle II[Go]({{< relref "/ChapterFour/0100~0199/0142.Linked-List-Cycle-II.md" >}})MediumO(n)O(1)❤️48.8%
0143Reorder List[Go]({{< relref "/ChapterFour/0100~0199/0143.Reorder-List.md" >}})MediumO(n)O(1)❤️52.6%
0146LRU Cache[Go]({{< relref "/ChapterFour/0100~0199/0146.LRU-Cache.md" >}})Medium40.7%
0147Insertion Sort List[Go]({{< relref "/ChapterFour/0100~0199/0147.Insertion-Sort-List.md" >}})MediumO(n)O(1)❤️51.1%
0148Sort List[Go]({{< relref "/ChapterFour/0100~0199/0148.Sort-List.md" >}})MediumO(n log n)O(n)❤️55.1%
0160Intersection of Two Linked Lists[Go]({{< relref "/ChapterFour/0100~0199/0160.Intersection-of-Two-Linked-Lists.md" >}})EasyO(n)O(1)❤️54.4%
0203Remove Linked List Elements[Go]({{< relref "/ChapterFour/0200~0299/0203.Remove-Linked-List-Elements.md" >}})EasyO(n)O(1)46.0%
0206Reverse Linked List[Go]({{< relref "/ChapterFour/0200~0299/0206.Reverse-Linked-List.md" >}})EasyO(n)O(1)73.6%
0234Palindrome Linked List[Go]({{< relref "/ChapterFour/0200~0299/0234.Palindrome-Linked-List.md" >}})EasyO(n)O(1)50.2%
0237Delete Node in a Linked List[Go]({{< relref "/ChapterFour/0200~0299/0237.Delete-Node-in-a-Linked-List.md" >}})MediumO(n)O(1)76.0%
0328Odd Even Linked List[Go]({{< relref "/ChapterFour/0300~0399/0328.Odd-Even-Linked-List.md" >}})MediumO(n)O(1)61.3%
0382Linked List Random Node[Go]({{< relref "/ChapterFour/0300~0399/0382.Linked-List-Random-Node.md" >}})Medium62.8%
0445Add Two Numbers II[Go]({{< relref "/ChapterFour/0400~0499/0445.Add-Two-Numbers-II.md" >}})MediumO(n)O(n)59.6%
0460LFU Cache[Go]({{< relref "/ChapterFour/0400~0499/0460.LFU-Cache.md" >}})Hard43.0%
0622Design Circular Queue[Go]({{< relref "/ChapterFour/0600~0699/0622.Design-Circular-Queue.md" >}})Medium51.5%
0705Design HashSet[Go]({{< relref "/ChapterFour/0700~0799/0705.Design-HashSet.md" >}})Easy65.6%
0706Design HashMap[Go]({{< relref "/ChapterFour/0700~0799/0706.Design-HashMap.md" >}})Easy64.7%
0707Design Linked List[Go]({{< relref "/ChapterFour/0700~0799/0707.Design-Linked-List.md" >}})MediumO(n)O(1)27.7%
0725Split Linked List in Parts[Go]({{< relref "/ChapterFour/0700~0799/0725.Split-Linked-List-in-Parts.md" >}})MediumO(n)O(1)57.2%
0817Linked List Components[Go]({{< relref "/ChapterFour/0800~0899/0817.Linked-List-Components.md" >}})MediumO(n)O(1)57.7%
0876Middle of the Linked List[Go]({{< relref "/ChapterFour/0800~0899/0876.Middle-of-the-Linked-List.md" >}})EasyO(n)O(1)❤️75.7%
1019Next Greater Node In Linked List[Go]({{< relref "/ChapterFour/1000~1099/1019.Next-Greater-Node-In-Linked-List.md" >}})MediumO(n)O(1)59.9%
1171Remove Zero Sum Consecutive Nodes from Linked List[Go]({{< relref "/ChapterFour/1100~1199/1171.Remove-Zero-Sum-Consecutive-Nodes-from-Linked-List.md" >}})Medium43.2%
1290Convert Binary Number in a Linked List to Integer[Go]({{< relref "/ChapterFour/1200~1299/1290.Convert-Binary-Number-in-a-Linked-List-to-Integer.md" >}})Easy82.1%
1669Merge In Between Linked Lists[Go]({{< relref "/ChapterFour/1600~1699/1669.Merge-In-Between-Linked-Lists.md" >}})Medium73.7%
1670Design Front Middle Back Queue[Go]({{< relref "/ChapterFour/1600~1699/1670.Design-Front-Middle-Back-Queue.md" >}})Medium57.2%
1721Swapping Nodes in a Linked List[Go]({{< relref "/ChapterFour/1700~1799/1721.Swapping-Nodes-in-a-Linked-List.md" >}})Medium67.1%
2181Merge Nodes in Between Zeros[Go]({{< relref "/ChapterFour/2100~2199/2181.Merge-Nodes-in-Between-Zeros.md" >}})Medium86.3%
------------------------------------------------------------------------------------------------------------------------------------------------