08/04/2019
Category: Array
Problem #: 1. Two Sum: HashMap
15. 3Sum : Set one target and flow from left to right
16. 3Sum Closest : Pretty same as 3Sum but more easy
18. 4Sum : Pretty same as 3Sum with one more exterior loop
08/05/2019
category: Array
26. Remove Duplicates from Sorted Array using a fast and slow pointer Watch out for the index.
80. Remove Duplicates from Sorted Array II : Same as the above one with one more flag to check if there's 3 duplicates
128. LOngest Consecutive Sequence: set a target, from both its left and right side, find the longest consequtive sequence, withe the use of hashset. Once an element was checked, it should be removed to save time.
27. Remove Element The same as 26, 80
283. MOve Zeroes The same as above.
31. Next Permutation 3steps, a. From right to left find the first one doesn't in ascending order, called target. b. From right to left find the first one larger than target, switch them. c. from the first right one of index of target, reverse to the end.
36. Valid SudoKu Using double loop and a HashSet, clearly add information of wether the particular number is in this row or column or block. For example, if a number has already existed in this row, if another one
also exists, it returns false.
08/06/2019
category: Array
42. Trapping Water https://www.cnblogs.com/wentiliangkaihua/p/10336711.html 1.find the peak 2. left to peak scan 3. right to peak scan
48. Rotate Image https://www.cnblogs.com/wentiliangkaihua/p/10341704.html 1. switch symmetrical lines(line i with line n-1-i, n is the length) 2. Transpose(转置, switch ij with ji)
66. Plus One https://www.cnblogs.com/wentiliangkaihua/p/11312861.html 1.Revesely deal with each digit, careful to carry digit.
70. Climbing Stairs https://www.cnblogs.com/wentiliangkaihua/p/10201202.html Iteration as what used in fibonacci. Or DP with the use of dp array.
73. Set Matrix Zeroes https://www.cnblogs.com/wentiliangkaihua/p/10476402.html The question asks O(m+n) for space instead of time. So firstly create two boolean array for column and row.
Scan every element, when 0 set certain array element to true. Then for row array directly scan for its true element and set other row element to 0 with Arrays.fill(matrix[i], 0)
For column array , if true, using an inner loop to scan each element, then the same as row array.
134. Gas Station https://www.cnblogs.com/wentiliangkaihua/p/10521358.html 设置两个变量,sum
判断当前的指针的有效性;total
则判断整个数组是否有解,有就返回通过sum
得到的下标,没有则返回-1。首先要跳过所有gas-cost小于0的点,因为从这些点永远不能开始。
135. Candy https://www.cnblogs.com/wentiliangkaihua/p/11313937.html 从左到右从右到左各扫描一遍,注意从右到左时注意不要多加一(比较当前element和右+1的大小,取大值)
08/07/2019
category: Array
169. Majority Element https://www.cnblogs.com/wentiliangkaihua/p/10618926.html Solution1: Using Arrays.sort(), and return the middle one, it has to be the majority. Solution2: Set 1st as target, when meeting with same, count ++, else count--. The final one must be majority.
189. Rotate Array https://www.cnblogs.com/wentiliangkaihua/p/10693706.html Create a new array a[], a[(i+k) % length] = nums[i], 很巧妙
219. Contains Duplicate II https://www.cnblogs.com/wentiliangkaihua/p/11318840.html 用hashmap来判决
217. Contains Duplicate https://www.cnblogs.com/wentiliangkaihua/p/11318837.html 用hashset添加元素,如果其size小于源数组就说明有duplicate
238. Product of Array Except Self https://www.cnblogs.com/wentiliangkaihua/p/11318843.html Create two arrays to store [1, a1, a1a2, a1a2a3] and [a4a3a2, a4a3, a4, 1]. Then multiply together.
334. Increasing Triplet Subsequence https://www.cnblogs.com/wentiliangkaihua/p/11319072.html
206. Reverse Linked List https://www.cnblogs.com/wentiliangkaihua/p/10345468.html 迭代:设置prev和cur两个指针,每次保存cur.next,一次reverse一个。递归:
head.next.next = head;
head.next = null;
328. Odd Even Linked List https://www.cnblogs.com/wentiliangkaihua/p/11320457.html Create two list: odd(based on original list) and even list. For each list, set the head and tail pointer.
08/09/2019
category: single linked list
2. Add Two Numbers https://www.cnblogs.com/wentiliangkaihua/p/11136055.html 加法的实现刚好是从最后一位开始加,先判断是否null,如果是就变0,然后相加,记录进位。用的是while循环
86. Partition List https://www.cnblogs.com/wentiliangkaihua/p/11330364.html Create 2 linked list , one stores value smaller than given number, the other stores equal or bigger ones. Finally the small point to the big, the big's next set to null.
92. Reverse Linked List II https://www.cnblogs.com/wentiliangkaihua/p/11330583.html
08/15/2019
category:single linked list
83. Remove Duplicates from sorted linked list https://www.cnblogs.com/wentiliangkaihua/p/10341623.html
08/20/2019
category:single linked list
61. Rotate List https://www.cnblogs.com/wentiliangkaihua/p/11386562.html
19. Remove Nth Node From End of List https://www.cnblogs.com/wentiliangkaihua/p/11386565.html
24. Swap Nodes in Pairs https://www.cnblogs.com/wentiliangkaihua/p/10337287.html
25. Reverse Nodes in k-Group https://www.cnblogs.com/wentiliangkaihua/p/10347469.html
08/21/2019
138. Copy List with Random Pointer https://www.cnblogs.com/wentiliangkaihua/p/10569269.html
141. Linked List Cycle https://www.cnblogs.com/wentiliangkaihua/p/10541410.html 快慢指针
142. Linked List Cycle II https://www.cnblogs.com/wentiliangkaihua/p/11392161.html 快慢指针拓展
143. Reorder List https://www.cnblogs.com/wentiliangkaihua/p/11392183.html
234. Palindrome Linked List https://www.cnblogs.com/wentiliangkaihua/p/11392187.html
Category: String
125. Valid Palindrome https://www.cnblogs.com/wentiliangkaihua/p/10505019.html
28. Implement strStr() https://www.cnblogs.com/wentiliangkaihua/p/10153583.html
67. Add Binary https://www.cnblogs.com/wentiliangkaihua/p/10166689.html
08/22/2019
Category: String
8. String to Integer (atoi) https://www.cnblogs.com/wentiliangkaihua/p/11397752.html
5. Longest Palindromic Substring https://www.cnblogs.com/wentiliangkaihua/p/11397396.html
10. Regular Expression Matching https://www.cnblogs.com/wentiliangkaihua/p/10353662.html
08/23/2019
Category: String
65. Valid Number https://www.cnblogs.com/wentiliangkaihua/p/11403201.html
14. Longest Common Prefix https://www.cnblogs.com/wentiliangkaihua/p/10141095.html
12. Integer to Roman https://www.cnblogs.com/wentiliangkaihua/p/11403393.html
13. Roman to Integer https://www.cnblogs.com/wentiliangkaihua/p/10141049.html
38. Count and Say https://www.cnblogs.com/wentiliangkaihua/p/10336371.html
49. Group Anagrams https://www.cnblogs.com/wentiliangkaihua/p/10349564.html
242. Valid Anagram https://www.cnblogs.com/wentiliangkaihua/p/11403476.html
08/24/2019
71. Simplify Path https://www.cnblogs.com/wentiliangkaihua/p/11406483.html
58. Length of Last Word https://www.cnblogs.com/wentiliangkaihua/p/10163224.html
205. Isomorphic Strings https://www.cnblogs.com/wentiliangkaihua/p/11406647.html
290. Word Pattern https://www.cnblogs.com/wentiliangkaihua/p/11406769.html
Category: Stack
155. Min Stack https://www.cnblogs.com/wentiliangkaihua/p/10612494.html
20. Valid Parentheses https://www.cnblogs.com/wentiliangkaihua/p/11406821.html
32. Longest Valid Parentheses https://www.cnblogs.com/wentiliangkaihua/p/11406881.html
08/26/2019
Category: Stack
150. Evaluate Reverse Polish Notation https://www.cnblogs.com/wentiliangkaihua/p/10569298.html
225. Implement Stack using Queues https://www.cnblogs.com/wentiliangkaihua/p/11415978.html
232. Implement Queue using Stacks https://www.cnblogs.com/wentiliangkaihua/p/11416616.html
144. Binary Tree Preorder Traversal https://www.cnblogs.com/wentiliangkaihua/p/11417286.html
94. Binary Tree Inorder Traversal https://www.cnblogs.com/wentiliangkaihua/p/10487193.html
08/27/2019
Category: Binary Tree
145. Binary Tree Postorder Traversal https://www.cnblogs.com/wentiliangkaihua/p/11421651.html
102. Binary Tree Level Order Traversal https://www.cnblogs.com/wentiliangkaihua/p/10493584.html
107. Binary Tree Level Order Traversal II 上面的用Collections.reverse()即可
199. Binary Tree Right Side View https://www.cnblogs.com/wentiliangkaihua/p/11421681.html 也是level order view上改动
226. Invert Binary Tree 层层遍历或递归
08/28/2019
Category: Binary Tree
遇到BST就要想起inorder,因为inorder下BST以从小到大排列。
173. Binary Search Tree Iterator Iterator包含next和hasNext方法,返回最小的elemengt就是求中序遍历
103. Binary Tree Zigzag Level Order Traversal Level Order traverse的变种,可以①先levelorder然后偶数level reverse,也可以②设置一个boolean 变量isLeftRight,每到下一层就取反,然后add(0, val)保证是reverse。
230. Kth Smallest Element in a BST
51. N-Queens https://www.cnblogs.com/wentiliangkaihua/p/10487182.html
1207. Unique Number of Occurrences hashmap.values是一个collections,可以用arraylist变成list
10/07/2019
123. Best Time to Buy and Sell Stock III https://www.cnblogs.com/wentiliangkaihua/p/11633310.html
10/09/2019
84. Largest Rectangle in Histogram https://www.cnblogs.com/wentiliangkaihua/p/10527833.html
85. Maximal Rectangle https://www.cnblogs.com/wentiliangkaihua/p/11645722.html
买卖股票 http://www.360doc.com/content/16/1004/16/10408243_595735141.shtml
188. Best Time to Buy and Sell Stock IV https://www.cnblogs.com/wentiliangkaihua/p/11647127.html
10/10/2019
309. Best Time to Buy and Sell Stock with Cooldown https://www.cnblogs.com/wentiliangkaihua/p/11653207.html
10/11/2019
64. Minimum Path Sum https://www.cnblogs.com/wentiliangkaihua/p/10487183.html
97. Interleaving String https://www.cnblogs.com/wentiliangkaihua/p/11658025.html
10/14/2019
72. Edit Distance https://www.cnblogs.com/wentiliangkaihua/p/11676110.html
91. Decode Ways https://www.cnblogs.com/wentiliangkaihua/p/11677104.html
10/15/2019
115. Distinct Subsequences https://www.cnblogs.com/wentiliangkaihua/p/11682193.html
139. Word Break https://www.cnblogs.com/wentiliangkaihua/p/10529133.html
10/16/2019
44. Wildcard Matching https://www.cnblogs.com/wentiliangkaihua/p/11689635.html
174. Dungeon Game https://www.cnblogs.com/wentiliangkaihua/p/11689711.html
198. House Robber https://www.cnblogs.com/wentiliangkaihua/p/10693760.html
213. House Robber II https://www.cnblogs.com/wentiliangkaihua/p/11690008.html
337. House Robber III https://www.cnblogs.com/wentiliangkaihua/p/11690409.html
303. Range Sum Query - Immutable https://www.cnblogs.com/wentiliangkaihua/p/11691017.html
304. Range Sum Query 2D - Immutable https://www.cnblogs.com/wentiliangkaihua/p/11691352.html
10/18/2019
133. Clone Graph https://www.cnblogs.com/wentiliangkaihua/p/11701682.html
190. Reverse Bits https://www.cnblogs.com/wentiliangkaihua/p/10693746.html
187. Repeated DNA Sequences https://www.cnblogs.com/wentiliangkaihua/p/11701690.html
191. Number of 1 Bits https://www.cnblogs.com/wentiliangkaihua/p/10693747.html
136. Single Number https://www.cnblogs.com/wentiliangkaihua/p/10521657.html
137. Single Number II https://www.cnblogs.com/wentiliangkaihua/p/10522060.html
260. Single Number III https://www.cnblogs.com/wentiliangkaihua/p/11702705.html
231. Power of Two https://www.cnblogs.com/wentiliangkaihua/p/11702711.html
326. Power of Three https://www.cnblogs.com/wentiliangkaihua/p/11702718.html
342. Power of Four https://www.cnblogs.com/wentiliangkaihua/p/11702720.html
268. Missing Number https://www.cnblogs.com/wentiliangkaihua/p/11702723.html