Linked List
Overview
1 | class ListNode: |
- Add a node into LinkedList is O(1).
- Remove a node from LinkedList is O(1) but search it is O(n).
Samples
Traversing and merge
No.2 - Add Two Numbers
Two pointers.
1 | def addTwoNumbers(self, l1: ListNode, l2: ListNode) -> ListNode: |
No.21 - Merge Two Sorted Lists
Several pointers.
No.23 - Merge k Sorted Lists
Priority queue
No.328 - Odd Even Linked List
Other basic function
No.237 - Delete Node in a Linked List
1 | def deleteNode(self, node): |
No.138 - Copy List with Random Pointer
Deep Copy
Recursively
No.206 - Reverse Linked List
No.234 - Palindrome Linked List
Combine with other data strucure
No.19 - Remove Nth Node From End of List
With List
No.206 - Reverse Linked List
Stack
No.141 - LinkeList List Cycle
HashTable
1 | def hasCycle(self, head): |
No.160 - Intersection of Two Linked Lists
HashTable
No.138 - Copy List with Random Pointer
HashTable