首先表達我對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