首先表达我对leetcode网站的感谢,与高校的OJ系统相比,leetcode上面的题目更贴近工作的需要,而且支持的语言广泛。对于一些比较困难的题目,可以从讨论区中学习别人的思路,这一点很方便。
经过一段时间的练习,我感觉自己的算法水平还是有很大的提升的。与学校开的算法导论的课程相比,我觉得实实在在的做题,比学习理论更符合我的认知方式。可能我属于那种脑子记不住,但是可以用“肌肉”去记忆的类型吧。
在做题的时候,我会尝试用感觉好玩的语言来写。如果把做题当成一种解谜游戏的话,那语言就是玩这个游戏选择的一个“职业”或者“角色”吧。每种语言都有自己的特色,喜欢哪个就用哪个。我会经常换换不同的口味,虽然写出来的代码奇形怪状,但是挺有意思的。
下面就是leetcode上的top 100题目的解答,原题目的链接是:https://leetcode.com/problemset/top-100-liked-questions/。
有些题目是参考别人的,但是未必有引用地址,如果哪位对内容有异议,可以给我留言。
整理这个列表,主要是用于我自己的总结,其中有些题目的代码还比较粗糙,我会抽时间回顾一下,不断的完善,也给有缘看到我的文章的朋友,提供一些方便。
1 Two Sum 42.20% Easy
2 Add Two Numbers 30.70% Medium
3 Longest Substring Without Repeating Characters 28.00% Medium
4 Median of Two Sorted Arrays 25.60% Hard
5 Longest Palindromic Substring 26.70% Medium
10 Regular Expression Matching 25.00% Hard
11 Container With Most Water 42.80% Medium
15 3Sum 23.50% Medium
17 Letter Combinations of a Phone Number 40.50% Medium
19 Remove Nth Node From End of List 34.00% Medium
20 Valid Parentheses 36.00% Easy
21 Merge Two Sorted Lists 46.00% Easy
22 Generate Parentheses 53.30% Medium
23 Merge k Sorted Lists 33.10% Hard
31 Next Permutation 30.10% Medium
32 Longest Valid Parentheses 25.00% Hard
33 Search in Rotated Sorted Array 32.70% Medium
34 Find First and Last Position of Element in Sorted Array 33.00% Medium
39 Combination Sum 46.90% Medium
42 Trapping Rain Water 42.00% Hard
45 Jump Game II 29.90% Hard
46 Permutations 53.60% Medium
48 Rotate Image 47.00% Medium
49 Group Anagrams 45.00% Medium
53 Maximum Subarray 42.90% Easy
55 Jump Game 31.40% Medium
56 Merge Intervals 34.90% Medium
62 Unique Paths 46.50% Medium
64 Minimum Path Sum 45.70% Medium
70 Climbing Stairs 43.50% Easy
72 Edit Distance 36.50% Hard
75 Sort Colors 41.40% Medium
76 Minimum Window Substring 29.90% Hard
78 Subsets 51.20% Medium
79 Word Search 30.50% Medium
84 Largest Rectangle in Histogram 30.30% Hard
85 Maximal Rectangle 32.50% Hard
94 Binary Tree Inorder Traversal 55.20% Medium
96 Unique Binary Search Trees 45.20% Medium
98 Validate Binary Search Tree 25.30% Medium
101 Symmetric Tree 42.80% Easy
102 Binary Tree Level Order Traversal 47.20% Medium
104 Maximum Depth of Binary Tree 59.30% Easy
105 Construct Binary Tree from Preorder and Inorder Traversal 39.60% Medium
114 Flatten Binary Tree to Linked List 41.20% Medium
121 Best Time to Buy and Sell Stock 46.30% Easy
124 Binary Tree Maximum Path Sum 29.40% Hard
128 Longest Consecutive Sequence 41.00% Hard
136 Single Number 59.10% Easy
139 Word Break 34.40% Medium
141 Linked List Cycle 35.90% Easy
142 Linked List Cycle II 31.00% Medium
146 LRU Cache 24.20% Medium
148 Sort List 34.10% Medium
152 Maximum Product Subarray 28.60% Medium
155 Min Stack 35.80% Easy
160 Intersection of Two Linked Lists 32.40% Easy
169 Majority Element 51.60% Easy
198 House Robber 40.80% Easy
200 Number of Islands 40.40% Medium
206 Reverse Linked List 52.90% Easy
207 Course Schedule 36.80% Medium
208 Implement Trie (Prefix Tree) 36.90% Medium
215 Kth Largest Element in an Array 46.20% Medium
221 Maximal Square 32.30% Medium
226 Invert Binary Tree 57.10% Easy
234 Palindrome Linked List 35.40% Easy
236 Lowest Common Ancestor of a Binary Tree 35.60% Medium
238 Product of Array Except Self 54.00% Medium
239 Sliding Window Maximum 37.20% Hard
240 Search a 2D Matrix II 40.30% Medium
253 Meeting Rooms II 42.30% Medium
279 Perfect Squares 41.00% Medium
283 Move Zeroes 53.70% Easy
287 Find the Duplicate Number 48.50% Medium
297 Serialize and Deserialize Binary Tree 39.50% Hard
300 Longest Increasing Subsequence 40.30% Medium
301 Remove Invalid Parentheses 38.50% Hard
309 Best Time to Buy and Sell Stock with Cooldown 43.50% Medium
312 Burst Balloons 46.40% Hard
322 Coin Change 29.20% Medium
337 House Robber III 47.40% Medium
338 Counting Bits 64.00% Medium
347 Top K Frequent Elements 53.60% Medium
394 Decode String 44.00% Medium
399 Evaluate Division 47.40% Medium
406 Queue Reconstruction by Height 59.00% Medium
416 Partition Equal Subset Sum 40.00% Medium
437 Path Sum III 42.00% Easy
438 Find All Anagrams in a String 36.50% Easy
448 Find All Numbers Disappeared in an Array 52.80% Easy
461 Hamming Distance 70.10% Easy
494 Target Sum 44.90% Medium
538 Convert BST to Greater Tree 50.00% Easy
543 Diameter of Binary Tree 46.20% Easy
560 Subarray Sum Equals K 41.70% Medium
581 Shortest Unsorted Continuous Subarray 29.60% Easy
617 Merge Two Binary Trees 69.30% Easy
621 Task Scheduler 44.50% Medium
647 Palindromic Substrings 56.00% Medium
739 Daily Temperatures 59.80% Medium
771 Jewels and Stones 83.00% Easy