LeetCode
我的LeetCode刷题、思路和代码总结, 以Top 100 liked & Top interviewed questions 为主(since 2020, 更新中).
部分题目待更新,题解将逐步完善.
Tag
Tag | 题解分类 |
---|---|
Array | 数组 |
Two Pointers | 双指针问题 |
DP | 动态规划 |
Tree | 树 |
Linked List | 链表 |
Subset | 子集问题 |
DFS | 深度优先搜索 |
BFS | 广度优先搜索 |
Binary Search | 二分查找 |
Graph | 图 |
Sliding Window | 滑动窗口问题 |
Merge Intervals | 区间合并问题 |
BackTracking | 回溯 |
Stack | 栈 |
Bit Manipulation | 位运算 |
Heap | 堆 |
Design | 设计题 |
String | 字符串 |
Palindrome | 回文串 |
题目列表
Two Pointers
- Pair with Target Sum (模板)
- Remove Duplicates (模板)
- Triplet Sum to Zero (模板)
- Subarrays with Product Less than a Target (medium)
- Dutch National Flag Problem (medium) / 三色旗 / 颜色分类
- 4Sum
- 1537. Get the Maximum Score (Hard)
- 42. Trapping Rain Water
DP
- 10. Regular Expression Matching 字符匹配
- 45. Jump Game 2
- 198. House Robber
- 337. House Robber III
- 256. Paint House
- 265. Paint House 2 (Hard)
- 221. Maximal Square (Medium)
- 494. Target Sum (Medium)
- 746. Min Cost Climbing Stairs
- 279. Perfect Squares
- 63. Unique Paths
- 322. Coin Change
- 518. Coin Change 2
- 486. Predict the Winner
- 377. Combination Sum IV
- 131. Palindrome Partitioning 最长回文串划分
- 516. Longest Palindromic Subsequence 最长回文串子序列个数
- 139. Word Break
- 1524. Number of Sub-arrays With Odd Sum
Tree
- 96. Unique Binary Search Tree
- 95. Unique Binary Search Trees II
- 98. Validate a BST
- 99. Recover Binary Search Tree (Hard)
- 100. Same Tree (easy)
- 101. Symmetric Tree (easy)
- 111. Minimum Depth of Binary Tree
- 105. Construct Binary Tree from Preorder and Inorder Traversal
- 108. Convert Sorted Array to Binary Search Tree (Easy)
- 107. 层序遍历
- 112. Path Sum
- 113. Path Sum II
- 116. Populating Next Right Pointers in Each Node
- 437. Path Sum III (easy)
- 124. Binary Tree Maximum Path Sum
- 306. Find Leaves of Binary Tree
- 701. Insert into a BST
- 572. Subtree of Another Tree
Linked List
- 19. Remove Nth Node From End of List
- 24. Swap Nodes in Pair
- 141. Linked List Cycle
- 160. Intersection of Two Linked Lists
- 109. Convert Sorted List to BST
- 206. Reverse Linked List (经典 每日一题)
- 25. Reverse Node in k-Group (经典 Hard)
- 92. Reverse Linked List II (经典)
- 328. Odd Even Linked List
Depth-First-Search
- 79. Word Search
- 130. Surrounded Regions
- 200. Numbers of Islands (三种方法, 经典)
- 694. Number of Distinct Islands
- 695. Max Area of Island
- 547. Friend Circles
- 733. Flood Fill (经典)
- 967. Numbers With Same Consecutive Differences
Breath-First-Search
Graph
- 207. Course Schedule (经典)
- 210. Course Schedule II (经典)
- 399. Evaluate Division (Graph + BFS)
- 269. Alien Dictionary (Graph + BFS)
- 1192. Critical Connections in a Network (Hard)
- 277. Find the Celebrity
- 863. All Nodes Distance K in Binary Tree
Binary Search
- 162. Find Peak Element
- 4. Median of Two Sorted Arrays (Hard)
- 729. My Calendar I
- 33. Search in Rotated Sorted Array
- 34. Find First and Last Position of Element in Sorted Array
- 74. Search a 2D Matrix
- 153. Find Minimum in Rotated Sorted Array
- 209. Minimum Size Subarray Sum
- 230. Kth Smallest Element in a BST
- 240. Search a 2D Matrix II
- 270. Closest Binary Search Tree Value
- 287. Find the Duplicate Number
- 300. Longest Increasing Subsequence
- 315. Count of Smaller Numbers After Self
- 374. Guess Number Higher or Lower
- 875. Koko Eating Bananas
- 1283. Find the Smallest Divisor Given a Threshold
- 1337. The K Weakest Rows in a Matrix
- 1351. Count Negative Numbers in a Sorted Matrix
Sliding Window
Merge Intervals
- 模板题: Merge Intervals (合并区间)
- 模板题: Insert Interval (插入区间)
- 模板题: Intervals Intersection (查找交集)
- 模板题: Conflicting Appointments (冲突区间)
- 模板题: Minimum Meeting Rooms (最少的会议室)
- Maximum CPU Load
- Employee Free Time (Hard)
- 729. My Calendar I
- 435. Non-overlapping Intervals (Greedy Method)
Subset
BackTracking
- 17. Letter Combinations of a Phone Number
- 22. Generate Parentheses
- 51. N皇后问题
- 46. Permutation
- 47. Permutations II
Stack
Heap / Heap Sort
- 973. K Closest Points to Origin (Medium)
- 378. Kth Smallest Element in a Sorted Matrix
- 295. Find Median from Data Stream (Hard)
Design
- 146. LRU Cache (每日一题)
- 380. Insert Delete GetRandom O(1) (每日一题)
- 208. Implement Trie (Prefix Tree)
- 212. Word Search II
- 211. Add and Search Word - Data structure design
- 1286. Iterator for Combination (Google)
- 1032. Stream of Characters (Use Trie)
Array
- 238. Product of Array Except Self
- 179. Largest Number
- 498. Diagonal Traverse
- 334. Increasing Triplet Subsequence
- 442. Find All Duplicates in an Array
- 406. Queue Reconstruction by Height
String
- 10. Regular Expression Matching 字符匹配
- 32. Longest Valid Parentheses (经典)
- 38. Count and Say
- 44. Wildcard Matching 万卡匹配
- 929. Unique Email Addresses
- 1041. Robot Bounded In Circle
- 763. Partition Labels
- 1505. Minimum Possible Integer After at Most K Adjacent Swaps On Digits
Palindrome
-
214. Shortest Palindrome (Hard)
-
234. Palindrome Linked List (Easy)
-
266. Palindrome Permutation (Easy)
-
336.Palindrome Pairs (Hard, Amazon)