leetcode
leetcode
leetcode
这是⼀本指导初学者刷题,并给出刷题顺序和分类的⼿册。
LeetCode是我们每个CS⼈都不得不面对的⼀道坎。但目前1400道LeetCode题⾜以“劝退”每⼀个想要
在北美找⼯转码的同学。在盲目开始之前,我们应该先思考如下⼏个问题:
刷多少题才够?
把⼀千多题题从头到尾刷完,对⼤多数⼈来说,是不现实也不值得提倡的,LeetCode题库相似题
型很多,刷题重在总结⽽不仅仅是数量,所以先给结论:
刷400道⾼频题完全⾜够。
要怎么刷才快?
接上面。400道题是否意味着从第1题刷到第400题呢,⽽⾼频题又是怎么定义的呢?
——这就是这本⼿册存在的意义。
⼀⾔以蔽之,刷题最重要的是要按分类刷,是要刷⾼频题,是要得出最优解,也要有⾼效率的重
复和⾼质量的总结。基于此,我们把 LeetCode做了⼀个分类:
1. 400题是我们从LeetCode1-1000题里挑选出来的⾼频(面试常出现)或有代表性(代表⼀整类题
型)的题目。
2. 对上述400题,本⼿册以tag为依据分⼤类,再以题型为依据分小类、旨在提供科学、⾼效的刷
题顺序。
关于我们
如果有同学想看到这些⾼频题的最优解讲解视频,请到www.flageek996.com购买后观看。
如果觉得直接上⼿LeetCode吃⼒,我们有算法专题课程(CS301A和CS301B)作为过渡;如果某⼀
块知识点是短板,那么专题系列课程(CS202/CS203/CS204/CS205)就是你的选择;对于刷题已经
过关的同学,简历修改服务(CS105)和模拟面试服务(CS502)也值得尝试。
这本刷题⼿册的内容会持续更新,题目也会不断补充。所有信息会统⼀在公众号和小助⼿朋友圈
发布,欢迎⼤家围观:
小助⼿微信:flageek996
公众号:FLAGeek频道
小助⼿微信 微信公众号
1
String
CS301B Chapter 2
2
CS301B Chapter 2
3
CS301B Chapter 2
巩固练习
1004 Max Consecutive Ones |||
811 Subdomain Visit Count
761 Special Binary String
981 Time Based Key-Value Store
4
Binary Search
CS301B Chapter 1
5
LinkedList
CS301A Chapter 3 & CS301B Chapter 3
6
Matrix
48 Rotate Image
54 Spiral Matrix
59 Spiral Matrix ||
74 Search a 2D Matrix
240 Search a 2D Matrix ||
498 Diagonal Traverse
311 Sparse Matrix Multiplication
79 Word Search
36 Valid Sudoku
37 Sudoku Solver
7
Math
1 Two sum
167 Two Sum II - Input array is sorted
15 3Sum
16 3Sum Closest
259 3Sum Smaller
18 4Sum
560 Subarray Sum Equals K
525 Contiguous Array
523 Continuous Subarray Sum
412 Fizz Buzz
7 Reverse Integer
165 Compare Version Numbers
66 Plus One
8 String to Integer (atoi)
258 Add Digits
67 Add Binary
43 Multiply Strings
29 Divide Two Integers
69 Sqrt(x)
50 Pow(x,n)
204 Count Primes
836 Rectangle Overlap
414 Third Maximum Number
593 Valid Square
892 Surface Area of 3D Shapes
390 Elimination Game
628 Maximum Product of Three Numbers
780 Reaching Points
829 Consecutive Numbers Sum
991 Broken Calculator
1041 Robot Bounded In Circle
8
Array
CS301A Chapter 2
27 Remove Element
26 Remove Duplicate from Sorted Array
80 Remove Duplicate from Sorted Array ||
316 Remove Duplicate Letters
442 Find All Duplicates in an Array
448 Find All Numbers Disappeared in an Array
325 Maximum Size Subarray Sum Equals k
581 Shortest Unsorted Continuous Subarray
277 Find the Celebrity
189 Rotate Array
384 Shuffle an Array
hard41 First Missing Positive
299 Bulls and Cows
845 Longest Mountain in Array
134 Gas Station
118 Pascal’s Triangle
119 Pascal’s Triangle ||
169 Majority Element
229 Majority Element ||
274 H-Index
275 H-Index ||
243 Shortest Word Distance
244 Shortest Word Distance ||
245 Shortest Word Distance |||
217 Contains Duplicate
219 Contains Duplicate ||
220 Contains Duplicate |||
55 Jump Game
45 Jump Game ||
307 Range Sum Query - Mutable
308 Range Sum Query 2D - Mutable
121 Best Time to Buy and Sell Stock
122 Best Time to Buy and Sell Stock ||
123 Best Time to Buy and Sell Stock |||
188 Best Time to Buy and Sell Stock IV
9
CS301A Chapter 2
10
CS301A Chapter 2
11
Tree
CS301A Chapter 6 & CS301B Chapter 9
12
CS301A Chapter 6 & CS301B Chapter 9
Tree类之“序列化Serialization”(第四类)
105 Construct Binary Tree from Preorder and Inorder Traversal
106 Construct Binary Tree from Inorder and Postorder Traversal
538 Convert BST to Greater Tree
108 Convert Sorted Array to Binary Search Tree
109 Convert Sorted List to Binary Search Tree
297 Serialize and Deserialize Binary Tree
Tree类之“去序列化Deserialization”(第五类)
449 Serialize and Deserialize Binary Search Tree
428 Serialize and Deserialize N-ary Tree
Tree类之“Level Order”(第六类)
107 Binary Tree Level Order Traversal ||
103 Binary Tree Zigzag Level Order Traversal
199 Binary Tree Right Side View
222 Count Complete Tree Nodes
102 Binary Tree Level Order Traversal
巩固练习
100 Same Tree
101 Symmetric Tree
226 Invert Binary Tree
255 Verify Preorder Sequence in Binary Search Tree
116 Populating Next Right Pointers in Each Node
117 Populating Next Right Pointers in Each Node ||
426 Convert Binary Search Tree to Sorted Doubly Linked List
958 Check Completeness of a Binary Tree
637 Average of Levels in Binary Tree
96 Unique Binary Search Trees
1130 Minimum Cost Tree From Leaf Values
1110 Delete Nodes And Return Forest
987 Vertical Order Traversal of a Binary Tree
545 Boundary of Binary Tree
742 Closest Leaf in a Binary Tree
156 Interleaving String
13
DFS & BFS
CS301B Chapter 5
14
CS301B Chapter 5
15
Stack
CS301A Chapter 5 & CS301B Chapter 7
16
PriorityQueue
CS301B Chapter 7
17
DP
CS205 DP专题
62 Unique Paths
63 Unique Paths ||
70 Climbing Stairs
120 Triangle
321 Create Maximum Number
518 Coin Change 2
139 Word Break
279 Perfect Squares
64 Minimum Path Sum
256 Paint House
718 Maximum Length of Repeated Subarray
416 Partition Equal Subset Sum
304 Range Sum Query 2D - Immutable
486 Predict the Winner
312 Burst Balloons
72 Edit Distance
221 Maximal Square
85 Maximal Rectangle
276 Paint Fence
198 House Robber
213 House Robber ||
53 Maximum Subarray
152 Maximum Product Subarray
1027 Longest Arithmetic Sequence
1048 Longest String Chain
10 Regular Expression Matching
740 Delete and Earn
97 Interleaving String
18
Bit Manipulation
19
Design
20
Graph
21