起因
俗话说的好,算法虐我千百遍,我待算法如初恋。
念叨着好好学算法很久了,念叨着刷leetcode也很久了,断断续续开始了几次,然而总是刷了几道就被虐的无心再战了,对我来说,这真是一个久攻不下的山头。还好我不害怕失败,我害怕没勇气继续挑战,多亏了年幼无知的时候喝了很多鸡汤,我总是有勇气继续去挑战自己。所以,我又开始了。
行动
其实一旦打定了主意,剩下的就是坚定不移的去填坑了。
我看了下commit提交记录,第一个commit是2017年11月17日,真棒,一段新旅程的开始。我心里开始慢慢有了方向,日子不再是随遇而安的,是有一个目的地我要去到达的。当时暗下决心要在农历年底前完成两百道题目。到2018年1月22日,已经完成了200道了,虽然大部分是简单和中等难度的,但这个小里程碑依然对我意味着很多。而且当时正好是秋冬季节,不能经常下了班去球场打球了,我开始办了健身卡,开始每周三四天下了班直奔健身房的日子。刷题和健身两条线齐头并进,那真是一段狂飙突进的日子。
当时的策略是,首先自己思考,如果有思路就尝试着写,没思路就看discuss或者网上搜一下解答。结果当然是很多都没思路,其实这也是很自然的,对于很多类型的题目来说,都是有专门的套路的,如果不了解这些套路,凭空来思考出答案,确实是非常难的。但是看到别人的解答,也一定要好好思考为什么这样做,尽量做到认真的看完一遍或几遍别人的解法,就能自己写出来,而不是看一点写一点。比较好的效果是,做过的题目,让你再做一次,你能完美解决,这也是我接下来的目标,更重视质量而不是数量。
所以呢?有进步吗?当然有进步了,很多算法和数据结构用起来更加游刃有余了,不过得承认,有一部分题的解法真的不好想,过一阵子可能就真的做不出来了。所以还是得多记笔记,勤于思考、总结。
下面是前300道算法题中觉得有必要记录下来的,好多是把我难住了的题, 老实说,有些题现在让我做我还是没啥好的思路。但是君子报仇十年不晚,我在小本本上把这些题记下来了,早晚搞定你。
后续还要继续坚持做,既然走在正确的道路上,那就要坚持走下去。
Part I
- 3. Longest Substring Without Repeating Characters
- 5. Longest Palindromic Substring
- 9. Palindrome Number
- 15. 3sum
- 16. 3Sum Closest
- 17. Letter Combinations of a Phone Number
- 18. 4Sum
- 19. Remove Nth Node From End of List
- 22. Generate Parentheses
- 26. Remove Duplicates from Sorted Array
- 27. Remove Element
- 31. Next Permutation
- 32. Longest Valid Parentheses
- 33. Search in Rotated Sorted Array
- 34. Search for a Range
- 39. Combination Sum
- 40. Combination Sum II
- 46. Permutations
- 47. Permutations II
- 48. Rotate Image
- 50. Pow(x, n)
- 53. Maximum Subarray
- 55. Jump Game
- 60. Permutation Sequence
- 62. Unique Paths
- 63. Unique Paths II
- 64. Minimum Path Sum
- 69. Sqrt(x)
- 70. Climbing Stairs
- 72. Edit Distance
- 73. Set Matrix Zeroes
- 75. Sort Colors
- 77. Combinations
- 79. Word Search
- 80. Remove Duplicates from Sorted Array II
- 81. Search in Rotated Sorted Array II
- 82. Remove Duplicates from Sorted List II
- 90. Subsets II
- 91. Decode Ways
- 93. Restore IP Addresses
- 94. Binary Tree Inorder Traversal
- 95. Unique Binary Search Trees II
- 96. Unique Binary Search Trees
- 98. Validate Binary Search Tree
- 99. recover Binary Search Tree
- 100. Same Tree
- 101. Symmetric Tree
- 102. Binary Tree Level Order Traversal
- 104. Maximum Depth of Binary Tree
- 105. Construct Binary Tree from Preorder and Inorder Traversal
- 108. Convert Sorted Array to Binary Search Tree
- 110. Balanced Binary Tree
- 111. Minimum Depth of Binary Tree
- 112. Path Sum
- 113. Path Sum II
- 114. Flatten Binary Tree to Linked List
- 118. Pascal’s Triangle
- 119. Pascal’s Triangle II
- 120. Triangle
- 121. Best Time to Buy and Sell Stock
- 122. Best Time to Buy and Sell Stock II
- 123. Best Time to Buy and Sell Stock III
- 129. Sum Root to Leaf Numbers
- 131. Palindrome Partitioning
- 134. Gas Station
- 138. Copy List with Random Pointer
- 139. Word Break
- 140. Word Break II
- 141. Linked List Cycle
- 144. Binary Tree Preorder Traversal
- 145. Binary Tree Postorder Traversal
- 152. Maximum Product Subarray
- 153. Find Minimum in Rotated Sorted Array
- 154. Find Minimum in Rotated Sorted Array II
- 188. Best Time to Buy and Sell Stock IV
- 204. Count Primes
- 209. Minimum Size Subarray Sum
- 215. Kth Largest Element in an Array
- 220. Contains Duplicate III
- 221. Maximal Square
- 235. Lowest Common Ancestor of a Binary Search Tree
- 236. Lowest Common Ancestor of a Binary Tree
- 239. Sliding Window Maximum
- 264. Ugly Number II
- 300. Longest Increasing Subsequence