刷题(和复习)

 

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
124. Binary Tree Maximum Path Sum https://www.cnblogs.com/wentiliangkaihua/p/11462725.html
117. Populating Next Right Pointers in Each Node II  https://www.cnblogs.com/wentiliangkaihua/p/11462748.html
129. Sum Root to Leaf Numbers  https://www.cnblogs.com/wentiliangkaihua/p/11463090.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  动态规划,贪心(从前到后,从后往前)

转载于:https://www.cnblogs.com/wentiliangkaihua/p/11302376.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值