刷题(和复习)

 

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

82. Remove Duplicates from sorted linked list II  https://www.cnblogs.com/wentiliangkaihua/p/11367147.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。

 08/29/2019
Category: Binary Tree
104. Maximum Depth of Binary Tree  https://www.cnblogs.com/wentiliangkaihua/p/10504051.html
114. Flatten Binary Tree to Linked List  https://www.cnblogs.com/wentiliangkaihua/p/11434149.html
116. Populating Next Right Pointers in Each Node  https://www.cnblogs.com/wentiliangkaihua/p/10509641.html
 08/30/2019
Category: Binary Tree
105. Construct Binary Tree from Preorder and Inorder Traversal  https://www.cnblogs.com/wentiliangkaihua/p/10504054.html
08/30/2019
Category: Binary Tree
106. Construct Binary Tree from Inorder and Postorder Traversal  https://www.cnblogs.com/wentiliangkaihua/p/11441287.html
09/01/2019
Category: Binary Tree
98. Validate Binary Search Tree  https://www.cnblogs.com/wentiliangkaihua/p/10528207.html
108. Convert Sorted Array to Binary Search Tree  https://www.cnblogs.com/wentiliangkaihua/p/10504814.html
109. Convert Sorted List to Binary Search Tree  https://www.cnblogs.com/wentiliangkaihua/p/11444486.html
235. Lowest Common Ancestor of a Binary Search Tree  https://www.cnblogs.com/wentiliangkaihua/p/11444491.html
09/02/2019
Category: Binary Tree

230. Kth Smallest Element in a BST

09/03/2019
Category: Binary Tree
111. Minimum Depth of Binary Tree  https://www.cnblogs.com/wentiliangkaihua/p/10504058.html
09/04/2019
Category: Binary Tree
117. Populating Next Right Pointers in Each Node II  https://www.cnblogs.com/wentiliangkaihua/p/11462748.html
236. Lowest Common Ancestor of a Binary Tree  https://www.cnblogs.com/wentiliangkaihua/p/11463514.html
09/06/2019
Category: 排序
09/09/2019
Category: 排序
215. Kth Largest Element in an Array  https://www.cnblogs.com/wentiliangkaihua/p/11495232.html
09/10/2019
Category: 排序
34. Find First and Last Position of Element in Sorted Array  https://www.cnblogs.com/wentiliangkaihua/p/10332409.html
09/11/2019
Category: search
33. Search in Rotated Sorted Array  https://www.cnblogs.com/grandyang/p/4325648.html
81. Search in Rotated Sorted Array II  https://www.cnblogs.com/wentiliangkaihua/p/11510998.html
09/12/2019
Category: search
153. Find Minimum in Rotated Sorted Array  https://www.cnblogs.com/wentiliangkaihua/p/11516045.html
154. Find Minimum in Rotated Sorted Array II  https://www.cnblogs.com/wentiliangkaihua/p/11516050.html
09/14/2019
Category: search
09/16/2019
09/17/2019
17. Letter Combinations of a Phone Number  https://www.cnblogs.com/wentiliangkaihua/p/10294161.html
09/18/2019
09/19/2019
DFS:
09/20/2019
DFS:
09/21/2019
DFS:
09/23/2019
 09/24/2019
79. Word Search  很多边界条件  https://www.cnblogs.com/wentiliangkaihua/p/10482687.html
55. Jump Game  https://www.cnblogs.com/wentiliangkaihua/p/10355826.html  动态规划,贪心(从前到后,从后往前)
09/25/2019
121. Best Time to Buy and Sell Stock   https://www.cnblogs.com/wentiliangkaihua/p/10386673.html 记录两个值
122. Best Time to Buy and Sell Stock II  https://www.cnblogs.com/wentiliangkaihua/p/10504917.html 加起来
3. Longest Substring Without Repeating Characters  https://www.cnblogs.com/wentiliangkaihua/p/10204173.html start,ans每次检查更新
11. Container With Most Water  https://www.cnblogs.com/wentiliangkaihua/p/11589804.html、双指针法
09/26/2019
09/27/2019
Dynamic Programming
300. Longest Increasing Subsequence   https://www.cnblogs.com/wentiliangkaihua/p/11601660.html
10/04/2019

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

2019/10/19

223. Rectangle Area  https://www.cnblogs.com/wentiliangkaihua/p/11706217.html

318. Maximum Product of Word Lengths  https://www.cnblogs.com/wentiliangkaihua/p/11706504.html

201. Bitwise AND of Numbers Range  https://www.cnblogs.com/wentiliangkaihua/p/11706615.html

202. Happy Number  https://www.cnblogs.com/wentiliangkaihua/p/10597917.html

263. Ugly Number  https://www.cnblogs.com/wentiliangkaihua/p/10597917.html

264. Ugly Number II  https://www.cnblogs.com/wentiliangkaihua/p/10540840.html

2019/10/20

151. Reverse Words in a String  https://www.cnblogs.com/wentiliangkaihua/p/11711405.html

2019/10/21

167. Two Sum II - Input array is sorted

2019/10/22

7. Reverse Integer  https://www.cnblogs.com/wentiliangkaihua/p/10135245.html

2019/10/25

56. Merge Intervals  https://www.cnblogs.com/wentiliangkaihua/p/10412265.html

57. Insert Intervals  https://www.cnblogs.com/wentiliangkaihua/p/10411878.html

76. Minimum Window Substring  https://www.cnblogs.com/wentiliangkaihua/p/10522441.html

43. Multiply Strings  https://www.cnblogs.com/wentiliangkaihua/p/10728738.html

2019/10/26

30. Substring with Concatenation of All Words  https://www.cnblogs.com/wentiliangkaihua/p/11746249.html

118. Pascal's Triangle  https://www.cnblogs.com/wentiliangkaihua/p/10495152.html

119. Pascal's Triangle II  https://www.cnblogs.com/wentiliangkaihua/p/11746362.html 

54. Spiral Matrix  https://www.cnblogs.com/wentiliangkaihua/p/10355799.html

59. Spiral Matrix II  https://www.cnblogs.com/wentiliangkaihua/p/10648193.html

6. ZigZag Conversion  https://www.cnblogs.com/wentiliangkaihua/p/11746505.html

2019/10/27

258. Add Digits  https://www.cnblogs.com/wentiliangkaihua/p/11750398.html

2019/10/28

165. Compare Version Numbers  https://www.cnblogs.com/wentiliangkaihua/p/11756531.html

140. Word Break II  https://www.cnblogs.com/wentiliangkaihua/p/11756559.html

146. LRU Cache  https://www.cnblogs.com/wentiliangkaihua/p/11756743.html

237. Delete Node in a Linked List  https://www.cnblogs.com/wentiliangkaihua/p/11757424.html

239. Sliding Window Maximum  https://www.cnblogs.com/wentiliangkaihua/p/11757862.html

2019/10/29

384. Shuffle an Array  https://www.cnblogs.com/wentiliangkaihua/p/11762645.html

279. Perfect Squares  https://www.cnblogs.com/wentiliangkaihua/p/11762648.html

287. Find the Duplicate Number  https://www.cnblogs.com/wentiliangkaihua/p/11763396.html

2019/10/30

289. Game of Life  https://www.cnblogs.com/wentiliangkaihua/p/11769447.html

295. Find Median from Data Stream  https://www.cnblogs.com/wentiliangkaihua/p/11770125.html

350. Intersection of Two Arrays II  https://www.cnblogs.com/wentiliangkaihua/p/11770482.html

2019/11/1

315. Count of Smaller Numbers After Self  https://www.cnblogs.com/wentiliangkaihua/p/11774858.html

324. Wiggle Sort II  https://www.cnblogs.com/wentiliangkaihua/p/11774877.html

2019/11/4

257. Binary Tree Paths

2019/11/5

278. First Bad Version  https://www.cnblogs.com/wentiliangkaihua/p/11802912.html

299. Bulls and Cows  https://www.cnblogs.com/wentiliangkaihua/p/11802915.html

292. Nim Game  https://www.cnblogs.com/wentiliangkaihua/p/11804137.html

2019/11/6

319. Bulb Switcher  https://www.cnblogs.com/wentiliangkaihua/p/11810987.html

329. Longest Increasing Path in a Matrix  https://www.cnblogs.com/wentiliangkaihua/p/11811268.html

2019/11/7

332. Reconstruct Itinerary  https://www.cnblogs.com/wentiliangkaihua/p/11817368.html

331. Verify Preorder Serialization of a Binary Tree  https://www.cnblogs.com/wentiliangkaihua/p/11824055.html

 

 

 

 

 

 

 

 

 

 

 

 

posted @ 2019-08-05 12:56  Schwifty  阅读(291)  评论(0编辑  收藏  举报