Skip to content

Latest commit

 

History

History
347 lines (345 loc) · 63.3 KB

README.md

File metadata and controls

347 lines (345 loc) · 63.3 KB

My LeetCode solutions with Chinese explanation. 我的LeetCode中文题解。
每个题目都保证击败超过80%的提交,并尽量给出多种解法并分析算法复杂度。
每日持续更新中,欢迎交流,欢迎star :D

另外,

  • algorithm文件夹对经典算法作了简单介绍并给出代码模板,方便刷题参考使用;
  • CodingInterview给出了《剑指offer》第2版中对应的LeetCode题目。
# 题目 题解 难度
1 Two Sum C++ Easy
2 Add Two Numbers C++ Medium
3 Longest Substring Without Repeating Characters C++ Medium
4 Median of Two Sorted Arrays C++ Hard
5 Longest Palindromic Substring C++ Medium
6 ZigZag Conversion C++ Medium
7 Reverse Integer C++ Easy
8 String to Integer (atoi) C++ Medium
9 Palindrome Number C++ Easy
10 Regular Expression Matching C++ Hard
11 Container With Most Water C++ Medium
12 Integer to Roman C++ Medium
13 Roman to Integer C++ Easy
14 Longest Common Prefix C++ Easy
15 3Sum C++ Medium
16 3Sum Closest C++ Medium
17 Letter Combinations of a Phone Number C++ Medium
18 4Sum C++ Medium
19 Remove Nth Node From End of List C++ Medium
20 Valid Parentheses C++ Easy
21 Merge Two Sorted Lists C++ Easy
22 Generate Parentheses C++ Medium
23 Merge k Sorted Lists C++ Hard
24 Swap Nodes in Pairs C++ Medium
26 Remove Duplicates from Sorted Array C++ Easy
27 Remove Element C++ Easy
28 Implement strStr() C++ Easy
29 Divide Two Integers C++ Medium
31 Next Permutation C++ Medium
32 Longest Valid Parentheses C++ Hard
33 Search in Rotated Sorted Array C++ Medium
34 Find First and Last Position of Element in Sorted C++ Medium
35 Search Insert Position C++ Easy
36 Valid Sudoku C++ Medium
38 Count and Say C++ Easy
39 Combination Sum C++ Medium
40 Combination Sum II C++ Medium
41 First Missing Positive C++ Hard
42 Trapping Rain Water C++ Hard
43 Multiply Strings C++ Medium
44 Wildcard Matching C++ Hard
45 Jump Game II C++ Hard
46 Permutations C++ Medium
47 Permutations II C++ Medium
48 Rotate Image C++ Medium
49 Group Anagrams C++ Medium
50 Pow(x, n) C++ Medium
53 Maximum Subarray C++ Easy
54 Spiral Matrix C++ Medium
55 Jump Game C++ Medium
56 Merge Intervals C++ Medium
58 Length of Last Word C++ Easy
59 Spiral Matrix II C++ Medium
60 Permutation Sequence C++ Medium
61 Rotate List C++ Medium
62 Unique Paths C++ Medium
63 Unique Paths II C++ Medium
64 Minimum Path Sum C++ Medium
65 Valid Number C++ Hard
66 Plus One C++ Easy
67 Add Binary C++ Easy
69 Sqrt(x) C++ Easy
70 Climbing Stairs C++ Easy
71 Simplify Path C++ Medium
72 Edit Distance C++ Hard
73 Set Matrix Zeroes C++ Medium
74 Search a 2D Matrix C++ Medium
75 Sort Colors C++ Medium
76 Minimum Window Substring C++ Hard
77 Combinations C++ Medium
78 Subsets C++ Medium
79 Word Search C++ Medium
80 Remove Duplicates from Sorted Array II C++ Medium
81 Search in Rotated Sorted Array II C++ Medium
82 Remove Duplicates from Sorted List II C++ Medium
83 Remove Duplicates from Sorted List C++ Easy
84 Largest Rectangle in Histogram C++ Hard
85 Maximal Rectangle C++ Hard
86 Partition List C++ Medium
88 Merge Sorted Array C++ Easy
89 Gray Code C++ Medium
90 Subsets II C++ Medium
91 Decode Ways C++ Medium
92 Reverse Linked List II C++ Medium
93 Restore IP Addresses C++ Medium
94 Binary Tree Inorder Traversal C++ Medium
95 Unique Binary Search Trees II C++ Medium
96 Unique Binary Search Trees C++ Medium
97 Interleaving String C++ Medium
98 Validate Binary Search Tree C++ Medium
99 Recover Binary Search Tree C++ Medium
100 Same Tree C++ Easy
101 Symmetric Tree C++ Easy
102 Binary Tree Level Order Traversal C++ Medium
103 Binary Tree Zigzag Level Order Traversal C++ Medium
104 Maximum Depth of Binary Tree C++ Easy
105 Construct Binary Tree from Preorder and Inorder Traversal C++ Medium
106 Construct Binary Tree from Inorder and Postorder Traversal C++ Medium
107 Binary Tree Level Order Traversal II C++ Easy
108 Convert Sorted Array to Binary Search Tree C++ Easy
109 Convert Sorted List to Binary Search Tree C++ Medium
110 Balanced Binary Tree C++ Easy
111 Minimum Depth of Binary Tree C++ Easy
112 Path Sum C++ Easy
113 Path Sum II C++ Medium
114 Flatten Binary Tree to Linked List C++ Medium
116 Populating Next Right Pointers in Each Node C++ Medium
117 Populating Next Right Pointers in Each Node II C++ Medium
118 Pascal's Triangle C++ Easy
119 Pascal's Triangle II C++ Easy
120 Triangle C++ Medium
121 Best Time to Buy and Sell Stock C++ Easy
122 Best Time to Buy and Sell Stock II C++ Easy
123 Best Time to Buy and Sell Stock III C++ Hard
124 Binary Tree Maximum Path Sum C++ Hard
125 Valid Palindrome C++ Easy
127 Word Ladder C++ Medium
128 Longest Consecutive Sequence C++ Hard
129 Sum Root to Leaf Numbers C++ Medium
130 Surrounded Regions C++ Medium
131 Palindrome Partitioning C++ Medium
133 Clone Graph C++ Medium
134 Gas Station C++ Medium
136 Single Number C++ Easy
137 Single Number II C++ Medium
138 Copy List with Random Pointer C++ Medium
139 Word Break C++ Medium
140 Word Break II C++ Hard
141 Linked List Cycle C++ Easy
142 Linked List Cycle II C++ Medium
143 Reorder List C++ Medium
144 Binary Tree Preorder Traversal C++ Medium
145 Binary Tree Postorder Traversal C++ Hard
146 LRU Cache C++ Medium
148 Sort List C++ Medium
149 Max Points on a Line C++ Hard
150 Evaluate Reverse Polish Notation C++ Medium
151 Reverse Words in a String C++ Medium
152 Maximum Product Subarray C++ Medium
153 Find Minimum in Rotated Sorted Array C++ Medium
155 Min Stack C++ Easy
160 Intersection of Two Linked Lists C++ Easy
162 Find Peak Element C++ Medium
165 Compare Version Numbers C++ Medium
166 Fraction to Recurring Decimal C++ Medium
167 Two Sum II - Input array is sorted C++ Easy
168 Excel Sheet Column Title C++ Easy
169 Majority Element C++ Easy
171 Excel Sheet Column Number C++ Easy
172 Factorial Trailing Zeroes C++ Easy
179 Largest Number C++ Medium
187 Repeated DNA Sequences C++ Medium
188 Best Time to Buy and Sell Stock IV C++ Hard
189 Rotate Array C++ Easy
190 Reverse Bits C++ Easy
191 Number of 1 Bits C++ Easy
198 House Robber C++ Easy
199 Binary Tree Right Side View C++ Medium
200 Number of Islands C++ Medium
201 Bitwise AND of Numbers Range C++ Medium
202 Happy Number C++ Easy
203 Remove Linked List Elements C++ Easy
204 Count Primes C++ Easy
205 Isomorphic Strings C++ Easy
206 Reverse Linked List C++ Easy
207 Course Schedule C++ Medium
208 Implement Trie (Prefix Tree) C++ Medium
209 Minimum Size Subarray Sum C++ Medium
210 Course Schedule II C++ Medium
211 Add and Search Word - Data structure design C++ Medium
212 Word Search II C++ Hard
213 House Robber II C++ Medium
215 Kth Largest Element in an Array C++ Medium
216 Combination Sum III C++ Medium
217 Contains Duplicate C++ Easy
218 The Skyline Problem C++ Hard
219 Contains Duplicate II C++ Easy
220 Contains Duplicate III C++ Medium
221 Maximal Square C++ Medium
222 Count Complete Tree Nodes C++ Medium
223 Rectangle Area C++ Medium
225 Implement Stack using Queues C++ Easy
226 Invert Binary Tree C++ Easy
227 Basic Calculator II C++ Medium
228 Summary Ranges C++ Medium
229 Majority Element II C++ Medium
230 Kth Smallest Element in a BST C++ Medium
231 Power of Two C++ Easy
232 Implement Queue using Stacks C++ Easy
233 Number of Digit One C++ Hard
234 Palindrome Linked List C++ Easy
235 Lowest Common Ancestor of a Binary Search Tree C++ Easy
236 Lowest Common Ancestor of a Binary Tree C++ Medium
237 Delete Node in a Linked List C++ Easy
238 Product of Array Except Self C++ Medium
239 Sliding Window Maximum C++ Hard
240 Search a 2D Matrix II C++ Medium
241 Different Ways to Add Parentheses C++ Medium
242 Valid Anagram C++ Easy
257 Binary Tree Paths C++ Easy
258 Add Digits C++ Easy
260 Single Number III C++ Medium
263 Ugly Number C++ Easy
264 Ugly Number II C++ Medium
268 Missing Number C++ Easy
274 H-Index C++ Medium
275 H-Index II C++ Medium
278 First Bad Version C++ Easy
279 Perfect Squares C++ Medium
283 Move Zeroes C++ Easy
284 Peeking Iterator C++ Medium
287 Find the Duplicate Number C++ Medium
289 Game of Life C++ Medium
290 Word Pattern C++ Easy
292 Nim Game C++ Easy
295 Find Median from Data Stream C++ Hard
297 Serialize and Deserialize Binary Tree C++ Hard
299 Bulls and Cows C++ Medium
300 Longest Increasing Subsequence C++ Medium
301 Remove Invalid Parentheses C++ Hard
303 Range Sum Query - Immutable C++ Easy
304 Range Sum Query 2D - Immutable C++ Medium
306 Additive Number C++ Medium
307 Range Sum Query - Mutable C++ Medium
309 Best Time to Buy and Sell Stock with Cooldown C++ Medium
310 Minimum Height Trees C++ Medium
312 Burst Balloons C++ Hard
313 Super Ugly Number C++ Medium
315 Count of Smaller Numbers After Self C++ Hard
316 Remove Duplicate Letters C++ Medium
318 Maximum Product of Word Lengths C++ Medium
319 Bulb Switcher C++ Medium
322 Coin Change C++ Medium
324 Wiggle Sort II C++ Medium
326 Power of Three C++ Easy
328 Odd Even Linked List C++ Medium
329 Longest Increasing Path in a Matrix C++ Hard
331 Verify Preorder Serialization of a Binary Tree C++ Medium
332 Reconstruct Itinerary C++ Medium
334 Increasing Triplet Subsequence C++ Medium
337 House Robber III C++ Medium
338 Counting Bits C++ Medium
341 Flatten Nested List Iterator C++ Medium
342 Power of Four C++ Easy
343 Integer Break C++ Medium
344 Reverse String C++ Easy
345 Reverse Vowels of a String C++ Easy
347 Top K Frequent Elements C++ Medium
349 Intersection of Two Arrays C++ Easy
350 Intersection of Two Arrays II C++ Easy
357 Count Numbers with Unique Digits C++ Medium
365 Water and Jug Problem C++ Medium
367 Valid Perfect Square C++ Easy
368 Largest Divisible Subset C++ Medium
371 Sum of Two Integers C++ Easy
372 Super Pow C++ Medium
373 Find K Pairs with Smallest Sums C++ Medium
374 Guess Number Higher or Lower C++ Easy
375 Guess Number Higher or Lower II C++ Medium
376 Wiggle Subsequence C++ Medium
377 Combination Sum IV C++ Medium
378 Kth Smallest Element in a Sorted Matrix C++ Medium
380 Insert Delete GetRandom O(1) C++ Medium
381 Insert Delete GetRandom O(1) - Duplicates allowed C++ Hard
382 Linked List Random Node C++ Medium
383 Ransom Note C++ Easy
384 Shuffle an Array C++ Medium
385 Mini Parser C++ Medium
386 Lexicographical Numbers C++ Medium
387 First Unique Character in a String C++ Easy
388 Longest Absolute File Path C++ Medium
389 Find the Difference C++ Easy
390 Elimination Game C++ Medium
392 Is Subsequence C++ Easy
393 UTF-8 Validation C++ Medium
394 Decode String C++ Medium
395 Longest Substring with At Least K Repeating Characters C++ Medium
396 Rotate Function C++ Medium
397 Integer Replacement C++ Medium
398 Random Pick Index C++ Medium
400 Nth Digit C++ Medium
401 Binary Watch C++ Easy
402 Remove K Digits C++ Medium
404 Sum of Left Leaves C++ Easy
405 Convert a Number to Hexadecimal C++ Easy
406 Queue Reconstruction by Height C++ Medium
409 Longest Palindrome C++ Easy
412 Fizz Buzz C++ Easy
413 Arithmetic Slices C++ Medium
414 Third Maximum Number C++ Easy
415 Add Strings C++ Easy
416 Partition Equal Subset Sum C++ Medium
429 N-ary Tree Level Order Traversal C++ Easy
434 Number of Segments in a String C++ Easy
437 Path Sum III C++ Easy
438 Find All Anagrams in a String C++ Easy
441 Arranging Coins C++ Easy
443 String Compression C++ Easy
447 Number of Boomerangs C++ Easy
448 Find All Numbers Disappeared in an Array C++ Easy
453 Minimum Moves to Equal Array Elements C++ Easy
454 4Sum II C++ Medium
455 Assign Cookies C++ Easy
459 Repeated Substring Pattern C++ Easy
461 Hamming Distance C++ Easy
463 Island Perimeter C++ Easy
474 Ones and Zeroes C++ Medium
475 Heaters C++ Easy
476 Number Complement C++ Easy
485 Max Consecutive Ones C++ Easy
493 Reverse Pairs C++ Hard
494 Target Sum C++ Medium
496 Next Greater Element I C++ Easy
500 Keyboard Row C++ Easy
509 Fibonacci Number C++ Easy
532 K-diff Pairs in an Array C++ Easy
543 Diameter of Binary Tree C++ Easy
560 Subarray Sum Equals K C++ Medium
561 Array Partition I C++ Easy
566 Reshape the Matrix C++ Easy
572 Subtree of Another Tree C++ Easy
581 Shortest Unsorted Continuous Subarray C++ Easy
605 Can Place Flowers C++ Easy
617 Merge Two Binary Trees C++ Easy
621 Task Scheduler C++ Medium
628 Maximum Product of Three Numbers C++ Easy
643 Maximum Average Subarray I C++ Easy
647 Palindromic Substrings C++ Medium
661 Image Smoother C++ Easy
665 Non-decreasing Array C++ Easy
714 Best Time to Buy and Sell Stock with Transaction Fee C++ Medium
739 Daily Temperatures C++ Medium
829 Consecutive Numbers Sum C++ Hard
846 Hand of Straights C++ Medium
905 Sort Array By Parity C++ Easy
946 Validate Stack Sequences C++ Medium
1155 Number of Dice Rolls With Target Sum C++ Medium