8000 key points · qinyafee/leetcode@1d930c5 · GitHub
[go: up one dir, main page]

Skip to content

Commit 1d930c5

Browse files
committed
key points
Signed-off-by: Qin Yafei <yafee.qin@gmail.com>
1 parent 79bcf65 commit 1d930c5

File tree

11 files changed

+410
-122
lines changed

11 files changed

+410
-122
lines changed

Keypoints.md

Lines changed: 285 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,285 @@
1+
2+
# 1.线性表
3+
4+
## 数组
5+
| # | Title | Difficulty | Solution |
6+
|---| ----- | -------- | ---------- |
7+
||Remove Duplicates from Sorted Array
8+
||Remove Duplicates from Sorted Array II
9+
||Longest Consecutive Sequence
10+
||Two Sum
11+
||3Sum
12+
||3Sum Closest
13+
||4Sum
14+
||Remove Element
15+
||Move Zeroes
16+
||Next Permutation
17+
||Permutation Sequence
18+
||Valid Sudoku
19+
||Trapping Rain Water
20+
||Rotate Image
21+
||Plus One
22+
||Climbing Stairs
23+
||Set Matrix Zeroes
24+
||Gas Station
25+
||Candy
26+
||Majority Element
27+
||Rotate Array
28+
||Contains Duplicate
29+
||Contains Duplicate II
30+
||Contains Duplicate III
31+
||Product of Array Except Self
32+
||Game of Life
33+
||Increasing Triplet Subsequence
34+
35+
## 单链表
36+
| # | Title | Difficulty | Solution |
37+
|---| ----- | -------- | ---------- |
38+
||Reverse Linked List
39+
||Odd Even Linked List
40+
||Add Two Numbers
41+
||Reverse Linked List II
42+
||Partition List
43+
||Remove Duplicates from Sorted List
44+
||Remove Duplicates from Sorted List II
45+
||Rotate List
46+
||Remove Nth Node From End of List
47+
||Swap Nodes in Pairs
48+
||Reverse Nodes in k-Group
49+
||Copy List with Random Pointer
50+
||Linked List Cycle
51+
||Linked List Cycle II
52+
||Reorder List
53+
||LRU Cache
54+
||Palindrome Linked List
55+
# 2.字符串
56+
| # | Title | Difficulty | Solution |
57+
|---| ----- | -------- | ---------- |
58+
||Valid Palindrome
59+
||Implement strStr
60+
||String to Integer (atoi)
61+
||Add Binary
62+
||**Longest Palindromic Substring**
63+
||Regular Expression Matching
64+
||Wildcard Matching
65+
||Longest Common Prefix
66+
||Valid Number
67+
||Integer to Roman
68+
||Roman to Integer
69+
||Count and Say
70+
||Anagrams
71+
||Valid Anagram
72+
||Simplify Path
73+
||Length of Last Word
74+
||Isomorphic Strings
75+
||Word Pattern
76+
# 3.栈和队列
77+
##
78+
| # | Title | Difficulty | Solution |
79+
|---| ----- | -------- | ---------- |
80+
||Min Stack
81+
||Valid Parentheses
82+
||Longest Valid Parentheses
83+
||Largest Rectangle in Histogram
84+
||Evaluate Reverse Polish Notation
85+
||Implement Stack using Queues
86+
## 队列
87+
||Implement Queue using Stacks
88+
89+
# 4.二叉树
90+
## 二叉树的遍历
91+
| # | Title | Difficulty | Solution |
92+
|---| ----- | -------- | ---------- |
93+
||Binary Tree Preorder Traversal
94+
||Binary Tree Inorder Traversal
95+
||Binary Tree Postorder Traversal
96+
||Binary Tree Level Order Traversal
97+
||Binary Tree Level Order Traversal II
98+
||Binary Tree Right Side View
99+
||Invert Binary Tree
100+
||Binary Search Tree Iterator
101+
||Binary Tree Zigzag Level Order Traversal
102+
||Recover Binary Search Tree
103+
||Same Tree
104+
||Symmetric Tree
105+
||Balanced Binary Tree
106+
||Flatten Binary Tree to Linked List
107+
||Populating Next Right Pointers in Each Node II
108+
## 二叉树的构建
109+
||Construct Binary Tree from Preorder and Inorder Traversal
110+
||Construct Binary Tree from Inorder and Postorder Traversal
111+
## 二叉查找树
112+
| # | Title | Difficulty | Solution |
113+
|---| ----- | -------- | ---------- |
114+
||Unique Binary Search Trees
115+
||Unique Binary Search Trees II
116+
||Validate Binary Search Tree
117+
||Convert Sorted Array to Binary Search Tree
118+
||Convert Sorted List to Binary Search Tree
119+
||LCA of BST
120+
||Kth Smallest Element in a BST
121+
## 二叉树的递归
122+
| # | Title | Difficulty | Solution |
123+
|---| ----- | -------- | ---------- |
124+
||Minimum Depth of Binary Tree
125+
||Maximum Depth of Binary Tree
126+
||Path Sum
127+
||Path Sum II
128+
||Binary Tree Maximum Path Sum
129+
||Populating Next Right Pointers in Each Node
130+
||Sum Root to Leaf Numbers
131+
||LCA of Binary Tree
132+
## 线段树
133+
||Range Sum Query - Mutable
134+
135+
# 5.排序
136+
## 插入排序
137+
Insertion Sort List
138+
## 归并排序
139+
Merge Two Sorted Arrays
140+
Merge Two Sorted Lists
141+
Merge k Sorted Lists
142+
Sort List
143+
## 快速排序
144+
Sort Colors
145+
Kth Largest Element in an Array
146+
## 桶排序
147+
First Missing Positive
148+
## 计数排序
149+
H-Index
150+
## 基数排序
151+
Maximum Gap
152+
## 其他
153+
Largest Number
154+
155+
# 6.查找
156+
| # | Title | Difficulty | Solution |
157+
|---| ----- | -------- | ---------- |
158+
||Search for a Range
159+
||Search Insert Position
160+
||Search in Rotated Sorted Array
161+
||Search in Rotated Sorted Array II
162+
||Search a 2D Matrix
163+
||Search a 2D Matrix II
164+
||Find Minimum in Rotated Sorted Array
165+
||Find Minimum in Rotated Sorted Array II
166+
||Median of Two Sorted Arrays
167+
||H-Index II
168+
# 7.暴力枚举法
169+
| # | Title | Difficulty | Solution |
170+
|---| ----- | -------- | ---------- |
171+
||Subsets
172+
||Subsets II
173+
||Permutations
174+
||Permutations II
175+
||Combinations
176+
||Letter Combinations of a Phone Number
177+
||# 8.广度优先搜索
178+
||Word Ladder
179+
||Word Ladder II
180+
||Surrounded Regions
181+
182+
# 9.深度优先搜索
183+
| # | Title | Difficulty | Solution |
184+
|---| ----- | -------- | ---------- |
185+
||Additive Number
186+
||Palindrome Partitioning
187+
||Unique Paths
188+
||Unique Paths II
189+
||N-Queens
190+
||N-Queens II
191+
||Restore IP Addresses
192+
||Combination Sum
193+
||Combination Sum II
194+
||Combination Sum III
195+
||Generate Parentheses
196+
||Sudoku Solver
197+
||Word Search
198+
199+
# 10.分治法
200+
||Pow(x,n)
201+
||Sqrt(x)
202+
# 11.贪心法
203+
| # | Title | Difficulty | Solution |
204+
|---| ----- | -------- | ---------- |
205+
||Jump Game
206+
||Jump Game II
207+
||Best Time to Buy and Sell Stock
208+
||Best Time to Buy and Sell Stock II
209+
||Longest Substring Without Repeating Characters
210+
||Container With Most Water
211+
||Patching Array
212+
# 12.动态规划
213+
| # | Title | Difficulty | Solution |
214+
|---| ----- | -------- | ---------- |
215+
|120|Triangle|
216+
||Maximum Subarray
217+
||Maximum Product Subarray
218+
||Longest Increasing Subsequence
219+
||Palindrome Partitioning II
220+
||Maximal Rectangle
221+
||Best Time to Buy and Sell Stock III
222+
||Best Time to Buy and Sell Stock IV
223+
||Best Time to Buy and Sell Stock with Cooldown
224+
||Interleaving String
225+
||Scramble String
226+
||Minimum Path Sum
227+
||Edit Distance
228+
||Decode Ways
229+
||Distinct Subsequences
230+
||Word Break
231+
||Word Break II
232+
||Dungeon Game
233+
||House Robber
234+
||House Robber II
235+
||House Robber III
236+
||Range Sum Query - Immutable
237+
||Range Sum Query 2D - Immutable
238+
239+
# 13.图
240+
||Clone Graph
241+
242+
# 14.位操作
243+
| # | Title | Difficulty | Solution |
244+
|---| ----- | -------- | ---------- |
245+
||Reverse Bits
246+
||Repeated DNA Sequences
247+
||Number of 1 Bits
248+
||Gray Code
249+
||Single Number
250+
||Single Number II
251+
||Single Number III
252+
||Power of Two
253+
||Missing Number
254+
||Maximum Product of Word Lengths
255+
||Bitwise AND of Numbers Range
256+
||Power of Three
257+
||Rectangle Area
258+
# 15.数论
259+
| # | Title | Difficulty | Solution |
260+
|---| ----- | -------- | ---------- |
261+
||Happy Number
262+
||Ugly Number
263+
||Ugly Number II
264+
||Super Ugly Number
265+
||Fraction to Recurring Decimal
266+
||Factorial Trailing Zeroes
267+
||Nim Game
268+
# 16.模拟
269+
| # | Title | Difficulty | Solution |
270+
|---| ----- | -------- | ---------- |
271+
||Reverse Integer
272+
||Palindrome Number
273+
||Insert Interval
274+
||Merge Intervals
275+
||Minimum Window Substring
276+
||Multiply Strings
277+
||Substring with Concatenation of All Words
278+
||Pascal's Triangle
279+
||Pascal's Triangle II
280+
||Spiral Matrix
281+
||Spiral Matrix II
282+
||ZigZag Conversion
283+
||Divide Two Integers
284+
||Text Justification
285+
||Max Points on a Line

algorithms/cpp/3Sum/3Sum.cpp

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -40,21 +40,21 @@ class Solution {
4040
sort(nums.begin(), nums.end());
4141

4242
for (int i = 0; i < n - 2; ++i) {
43-
if (nums[i] > 0) { //已排序,后面不会有解
43+
if (nums[i] > 0) { // 已排序,后面不会有解
4444
return res;
4545
}
46-
if (i > 0 && nums[i] == nums[i-1]) { // 去重复
46+
if (i > 0 && nums[i] == nums[i - 1]) { //! 去重复
4747
continue;
4848
}
4949
auto left = i + 1;
5050
auto right = n - 1;
5151
while (left < right) {
5252
if (nums[i] + nums[left] + nums[right] == 0) {
5353
res.push_back({nums[i], nums[left], nums[right]});
54-
++left; //找下一个解
55-
--right; //找下一个解
56-
while (nums[left] == nums[left-1] && left < right) ++left; //去重复
57-
while (nums[right] == nums[right + 1] && left < right) --right; //去重复
54+
++left; //! 找下一个解
55+
--right; //! 找下一个解
56+
while (nums[left] == nums[left - 1] && left < right) ++left; // 去重复
57+
while (nums[right] == nums[right + 1] && left < right) --right; // 去重复
5858

5959
} else if (nums[i] + nums[left] + nums[right] < 0) {
6060
++left;
@@ -79,17 +79,17 @@ class Solution {
7979
sort(nums.begin(), nums.end());
8080
auto last = nums.end();
8181
for (auto i = nums.begin(); i < last - 2; ++i) {
82-
if (*i > 0) return res; //已排序,后面不会有解
83-
if (i > nums.begin() && *i == *(i - 1)) continue; //去重复
82+
if (*i > 0) return res; // 已排序,后面不会有解
83+
if (i > nums.begin() && *i == *(i - 1)) continue; // 去重复
8484
auto left = i + 1;
8585
auto right = last - 1;
8686
while (left < right) {
8787
if (*i + *left + *right == 0) {
8888
res.push_back({*i, *left, *right});
89-
++left; //找下一个解
90-
--right; //找下一个解
91-
while (*left == *(left - 1) && left < right) ++left; //去重复
92-
while (*right == *(right + 1) && left < right) --right; //去重复
89+
++left; // 找下一个解
90+
--right; // 找下一个解
91+
while (*left == *(left - 1) && left < right) ++left; // 去重复
92+
while (*right == *(right + 1) && left < right) --right; // 去重复
9393

9494
} else if (*i + *left + *right < 0) {
9595
++left;
@@ -105,6 +105,7 @@ class Solution {
105105
};
106106

107107
#include <stdio.h>
108+
108109
#include <algorithm>
109110
#include <iostream>
110111
#include <set>

algorithms/cpp/3SumClosest/3SumClosest.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ class Solution {
2626
const int n = nums.size();
2727
int res = 0;
2828
int min_gap = INT_MAX;
29-
sort(nums.begin(), nums.end()); //先排序
29+
sort(nums.begin(), nums.end()); // 先排序
3030
for (int i = 0; i < n - 2; ++i) { // i<倒数第二个
31-
int left = i+1;
32-
int right = n-1;
31+
int left = i + 1;
32+
int right = n - 1;
3333
while (left < right) {
3434
const int sum = nums[i] + nums[left] + nums[right];
3535
const int gap = abs(sum - target);
@@ -55,7 +55,7 @@ class Solution {
5555
// if(nums.size() < 3) return;
5656
int res = 0;
5757
int min_gap = INT_MAX;
58-
sort(nums.begin(), nums.end()); //先排序
58+
sort(nums.begin(), nums.end()); // 先排序
5959
for (auto i = nums.begin(); i < prev(nums.end(), 2); ++i) { // i<倒数第二个
6060
auto left = next(i);
6161
auto right = prev(nums.end());
@@ -79,6 +79,7 @@ class Solution {
7979

8080
#include <stdio.h>
8181
#include <stdlib.h>
82+
8283
#include <algorithm>
8384
#include <iostream>
8485
#include <set>

0 commit comments

Comments
 (0)
0