|
18 | 18 | | 15 | [3Sum](https://leetcode.com/problems/3sum/) | [Python](https://github.com/qiyuangong/leetcode/blob/master/python/15_3Sum.py) | 1. Sort and O(n^2) search with three points <br>2. Multiple Two Sum (Problem 1) |
|
19 | 19 | | 16 | [3Sum Closest](https://leetcode.com/problems/3sum-closest/) | [Python](https://github.com/qiyuangong/leetcode/blob/master/python/16_3Sum_Closest.py) | Sort and Multiple Two Sum check abs|
|
20 | 20 | | 18 | [4Sum](https://leetcode.com/problems/4sum/) | [Python](https://github.com/qiyuangong/leetcode/blob/master/python/18_4Sum.py) | The same as 3Sum, but we can merge pairs with the same sum |
|
| 21 | +| 20 | [Valid Parentheses](https://leetcode.com/problems/valid-parentheses/) | [Python](https://github.com/qiyuangong/leetcode/blob/master/python/20_Valid_Parentheses.py) | 1. Stack<br>2. Replace all parentheses with '', if empty then True | |
21 | 22 | | 21 | [Merge Two Sorted Lists](https://leetcode.com/problems/merge-two-sorted-lists/) | [Python](https://github.com/qiyuangong/leetcode/blob/master/python/21_Merge_Two_Sorted_Lists.py) | Add a dummy head, then merge two sorted list in O(m+n) |
|
22 | 23 | | 23 | [Merge k Sorted Lists](https://leetcode.com/problems/merge-k-sorted-lists/) | [Python](https://github.com/qiyuangong/leetcode/blob/master/python/23_Merge_k_Sorted_Lists.py) | 1. Priority queue O(nk log k)<br>2. Binary merge O(nk log k)| |
|
23 | 24 | | 24 | [Swap Nodes in Pairs](https://leetcode.com/problems/swap-nodes-in-pairs/) | [Python](https://github.com/qiyuangong/leetcode/blob/master/python/24_Swap_Nodes_in_Pairs.py) | Add a dummy and store the prev |
|
|
34 | 35 | | 111 | [Minimum Depth of Binary Tree](https://leetcode.com/problems/minimum-depth-of-binary-tree/) | [Python](https://github.com/qiyuangong/leetcode/blob/master/python/111_Minimum_Depth_of_Binary_Tree.py) | 1. Recursion, note that when size of left (ld) or right (rd) is 0, then min = 1 + ld + rd<br> 2. BFS check by level (right most), which is much faster than recursion |
|
35 | 36 | | 124 | [Binary Tree Maximum Path Sum](https://leetcode.com/problems/binary-tree-maximum-path-sum/) | [Python](https://github.com/qiyuangong/leetcode/blob/master/python/124. Binary Tree Maximum Path Sum.py) | Recursion O(n) and O(n), max (left + node, right + node, left + node + right) |
|
36 | 37 | | 125 | [Valid Palindrome](https://leetcode.com/problems/valid-palindrome/) | [Python](https://github.com/qiyuangong/leetcode/blob/master/python/125_Valid_Palindrome.py)| Exclude non-alphanumeric characters and compare O(n) |
|
| 38 | +| 133 | [Clone Graph](https://leetcode.com/problems/clone-graph/) | [Python](https://github.com/qiyuangong/leetcode/blob/master/python/133_Clone_Graph.py) | Hash and DFS or BFS | |
37 | 39 | | 136 | [Single Number](https://leetcode.com/problems/single-number/) | [Python](https://github.com/qiyuangong/leetcode/blob/master/python/136_Single_Number.py) | 1. Hash or set, O(n) and O(n)<br>2. xor O(n) and O(1) |
|
38 | 40 | | 137 | [Single Number II](https://leetcode.com/problems/single-number-ii/) | [Python](https://github.com/qiyuangong/leetcode/blob/master/python/137_Single_Number_II.py) | 1. ctypes 32 % 3 and &, O(n) and O(1)<br>2. ones, twos, threes as bitmask (e.g. ones represents ith bit had appeared once), O(n) and O(1) |
|
39 |
| -| 138 | [Copy List with Random Pointer](https://leetcode.com/problems/copy-list-with-random-pointer/) | [Python](https://github.com/qiyuangong/leetcode/blob/master/python/138_Copy_List_with_Random_Pointer.py) | 1. Hash O(n) and O(n)<br>2. Modify original structure: Original->Copy->Original, then node.next.random = node.random.next, O(n) and O(1)| |
| 41 | +| 138 | [Copy List with Random Pointer](https://leetcode.com/problems/copy-list-with-random-pointer/) | [Python](https://github.com/qiyuangong/leetcode/blob/master/python/138_Copy_List_with_Random_Pointer.py) | 1. Hash O(n) and O(n)<br>2. Modify original structure: Original->Copy->Original, then node.next.random = node.random.next, O(n) and O(1) | |
| 42 | +| 150 | [Evaluate Reverse Polish Notation](https://leetcode.com/problems/evaluate-reverse-polish-notation/) | [Python](https://github.com/qiyuangong/leetcode/blob/master/python/150_Evaluate_Reverse_Polish_Notation.py) | Stack | |
40 | 43 | | 151 | [Reverse Words in a String](https://discuss.leetcode.com/category/159/reverse-words-in-a-string) | [Python](https://github.com/qiyuangong/leetcode/blob/master/python/151_Reverse_Words_in_a_String.py)| 1. Python split by space <br>2. Reverse all and reverse words |
|
| 44 | +| 155 | [Min Stack](https://leetcode.com/problems/min-stack/) | [Python](https://github.com/qiyuangong/leetcode/blob/master/python/155_Min_Stack.py) | Add another stack for min stack, maintance this stack when the main stack pop or push | |
41 | 45 | | 156 | [Binary Tree Upside Down](https://leetcode.com/problems/binary-tree-upside-down/) ♥| [Python](https://github.com/qiyuangong/leetcode/blob/master/python/156_Binary_Tree_Upside_Down.py) | p.left = parent.right, parent.right = p.right, p.right = parent, parent = p.left, p = left |
|
42 | 46 | | 157 | [Read N Characters Given Read4](https://leetcode.com/problems/read-n-characters-given-read4/) ♥ | [Python](https://github.com/qiyuangong/leetcode/blob/master/python/157_Read_N_Characters_Given_Read4.py) | Handle the edge case (the end) |
|
43 | 47 | | 158 | [Read N Characters Given Read4 II - Call multiple times](https://leetcode.com/problems/read-n-characters-given-read4-ii-call-multiple-times/) ♥| [Python](https://github.com/qiyuangong/leetcode/blob/master/python/158_Read_N_Characters_Given_Read4_II_Call_multiple_times.py) | Store the pos and offset that is read by last read4 |
|
|
0 commit comments