|
12 | 12 | | 5 | [Longest Palindromic Substring](https://leetcode.com/problems/longest-palindromic-substring/) | [Python](https://github.com/qiyuangong/leetcode/blob/master/python/5_Longest_Palindromic_Substring.py) | [Background knowledge](http://en.wikipedia.org/wiki/Longest_palindromic_substring)<br>1. DP if s[i]==s[j] and P[i+1, j-1] then P[i,j]<br>2. A palindrome can be expanded from its center<br>3. Manacher algorithm|
|
13 | 13 | | 7 | [Reverse Integer](https://leetcode.com/problems/reverse-integer/) | [Python](https://github.com/qiyuangong/leetcode/blob/master/python/7_Reverse_Integer.py) | Overflow when the result is greater than 2147483647
|
14 | 14 | | 8 | [String to Integer (atoi)](https://leetcode.com/problems/string-to-integer-atoi/) | [Python](https://github.com/qiyuangong/leetcode/blob/master/python/8_String_to_Integer(atoi).py) | Overflow, Space, and negative number |
|
15 |
| -| 9 | [Palindrome Number](https://leetcode.com/problems/palindrome-number/) | [Python](https://github.com/qiyuangong/leetcode/blob/master/python/9_Palindrome_Number.py)| Get the len and check left and right with 10^len, 10| |
| 15 | +| 9 | [Palindrome Number](https://leetcode.com/problems/palindrome-number/) | [Python](https://github.com/qiyuangong/leetcode/blob/master/python/9_Palindrome_Number.py)| Get the len and check left and right with 10^len, 10 | |
| 16 | +| 12 | [Integer to Roman](https://leetcode.com/problems/integer-to-roman/) | [Python](https://github.com/qiyuangong/leetcode/blob/master/python/12_Integer_to_Roman.py) | [Background knowledge](http://www.rapidtables.com/convert/number/how-number-to-roman-numerals.htm) Just like 10-digit number, divide and minus | |
| 17 | +| 13 | [Roman to Integer](https://leetcode.com/problems/roman-to-integer/) | [Python](https://github.com/qiyuangong/leetcode/blob/master/python/13_Roman_to_Integer.py) | Add all curr, if curr > prev, then need to subtract 2 * prev | |
16 | 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) |
|
17 | 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|
|
18 | 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 |
|
19 | 21 | | 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) |
|
20 | 22 | | 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)| |
|
21 | 23 | | 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 |
|
22 | 24 | | 28 | [Implement strStr()](https://leetcode.com/problems/implement-strstr/) | [Python](https://github.com/qiyuangong/leetcode/blob/master/python/28_Implement_strStr().py) | 1. O(nm) comparison <br>2. KMP |
|
| 25 | +| 54 | [Spiral Matrix](https://leetcode.com/problems/spiral-matrix/) | [Python](https://github.com/qiyuangong/leetcode/blob/master/python/54_Spiral_Matrix.py) | O(nm) 1. Turn in the corner and loop<br>2. (0, 1) -> (1, 0) -> (0, -1) -> (-1, 0) | |
23 | 26 | | 65 | [Valid Number](https://leetcode.com/problems/valid-number/) | [Python](https://github.com/qiyuangong/leetcode/blob/master/python/65_Valid_Number.py) | 1. strip leading and tailing space, then check float using exception, check e using split <br>2. check is number split by . or e, note that number after e may be negative |
|
24 | 27 | | 66 | [Plus One](https://leetcode.com/problems/plus-one/) | [Python](https://github.com/qiyuangong/leetcode/blob/master/python/66_Plus_One.py) | Check if current digit == 9. |
|
25 | 28 | | 72 | [Edit Distance](https://leetcode.com/problems/edit-distance/) | [Python](https://github.com/qiyuangong/leetcode/blob/master/python/72_Edit_Distance.py) | [Background](https://en.wikipedia.org/wiki/Edit_distance)<br> 1. DP O(n^2) space<br>2. DP O(n) space |
|
|
31 | 34 | | 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 |
|
32 | 35 | | 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) |
|
33 | 36 | | 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) |
|
34 |
| -| 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) | |
| 37 | +| 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 | +| 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) | |
35 | 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)|
|
36 | 40 | | 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 |
|
37 | 41 | | 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 |
|
|
0 commit comments