面试经典 150 题
最经典 150 题,掌握面试所有知识点
数组 / 字符串
24 题| 顺序 | 难度 | 题目 |
|---|---|---|
| 1 | 简单 | 合并两个有序数组#88 Merge Sorted Array |
| 2 | 简单 | 移除元素#27 Remove Element |
| 3 | 简单 | 删除有序数组中的重复项#26 Remove Duplicates from Sorted Array |
| 4 | 中等 | Remove Duplicates from Sorted Array II |
| 5 | 简单 | 多数元素#169 Majority Element |
| 6 | 中等 | 轮转数组#189 Rotate Array |
| 7 | 简单 | 买卖股票的最佳时机#121 Best Time to Buy and Sell Stock |
| 8 | 中等 | 买卖股票的最佳时机 II#122 Best Time to Buy and Sell Stock II |
| 9 | 中等 | 跳跃游戏#55 Jump Game |
| 10 | 中等 | 跳跃游戏 II#45 Jump Game II |
| 11 | 中等 | H 指数#274 H-Index |
| 12 | 中等 | Insert Delete GetRandom O(1) |
| 13 | 中等 | 除了自身以外数组的乘积#238 Product of Array Except Self |
| 14 | 中等 | 加油站#134 Gas Station |
| 15 | 困难 | 分发糖果#135 Candy |
| 16 | 困难 | Trapping Rain Water |
| 17 | 简单 | 罗马数字转整数#13 Roman to Integer |
| 18 | 中等 | 整数转罗马数字#12 Integer to Roman |
| 19 | 简单 | 最后一个单词的长度#58 Length of Last Word |
| 20 | 简单 | 最长公共前缀#14 Longest Common Prefix |
| 21 | 中等 | 反转字符串中的单词#151 Reverse Words in a String |
| 22 | 中等 | Z 字形变换#6 Zigzag Conversion |
| 23 | 简单 | Find the Index of the First Occurrence in a String |
| 24 | 困难 | 文本左右对齐#68 Text Justification |
- #1简单#88
Merge Sorted Array
- #2简单#27
Remove Element
- #3简单#26
Remove Duplicates from Sorted Array
- #4中等#80
Remove Duplicates from Sorted Array II
- #5简单#169
Majority Element
- #6中等#189
Rotate Array
- #7简单#121
Best Time to Buy and Sell Stock
- #8中等#122
Best Time to Buy and Sell Stock II
- #9中等#55
Jump Game
- #10中等#45
Jump Game II
- #11中等#274
H-Index
- #12中等#380
Insert Delete GetRandom O(1)
- #13中等#238
Product of Array Except Self
- #14中等#134
Gas Station
- #15困难#135
Candy
- #16困难#42站内精讲
Trapping Rain Water
- #17简单#13
Roman to Integer
- #18中等#12
Integer to Roman
- #19简单#58
Length of Last Word
- #20简单#14
Longest Common Prefix
- #21中等#151
Reverse Words in a String
- #22中等#6
Zigzag Conversion
- #23简单#28
Find the Index of the First Occurrence in a String
- #24困难#68
Text Justification
双指针
5 题| 顺序 | 难度 | 题目 |
|---|---|---|
| 25 | 简单 | 验证回文串#125 Valid Palindrome |
| 26 | 简单 | 判断子序列#392 Is Subsequence |
| 27 | 中等 | Two Sum II - Input Array Is Sorted |
| 28 | 中等 | Container With Most Water |
| 29 | 中等 | 3Sum |
- #25简单#125
Valid Palindrome
- #26简单#392
Is Subsequence
- #27中等#167站内精讲
Two Sum II - Input Array Is Sorted
- #28中等#11站内精讲
Container With Most Water
- #29中等#15站内精讲
3Sum
滑动窗口
4 题| 顺序 | 难度 | 题目 |
|---|---|---|
| 30 | 中等 | 长度最小的子数组#209 Minimum Size Subarray Sum |
| 31 | 中等 | Longest Substring Without Repeating Characters |
| 32 | 困难 | 串联所有单词的子串#30 Substring with Concatenation of All Words |
| 33 | 困难 | Minimum Window Substring |
- #30中等#209
Minimum Size Subarray Sum
- #31中等#3站内精讲
Longest Substring Without Repeating Characters
- #32困难#30
Substring with Concatenation of All Words
- #33困难#76站内精讲
Minimum Window Substring
矩阵
5 题| 顺序 | 难度 | 题目 |
|---|---|---|
| 34 | 中等 | 有效的数独#36 Valid Sudoku |
| 35 | 中等 | 螺旋矩阵#54 Spiral Matrix |
| 36 | 中等 | 旋转图像#48 Rotate Image |
| 37 | 中等 | 矩阵置零#73 Set Matrix Zeroes |
| 38 | 中等 | 生命游戏#289 Game of Life |
- #34中等#36
Valid Sudoku
- #35中等#54
Spiral Matrix
- #36中等#48
Rotate Image
- #37中等#73
Set Matrix Zeroes
- #38中等#289
Game of Life
哈希表
9 题| 顺序 | 难度 | 题目 |
|---|---|---|
| 39 | 简单 | 赎金信#383 Ransom Note |
| 40 | 简单 | 同构字符串#205 Isomorphic Strings |
| 41 | 简单 | 单词规律#290 Word Pattern |
| 42 | 简单 | 有效的字母异位词#242 Valid Anagram |
| 43 | 中等 | Group Anagrams |
| 44 | 简单 | Two Sum |
| 45 | 简单 | 快乐数#202 Happy Number |
| 46 | 简单 | 存在重复元素 II#219 Contains Duplicate II |
| 47 | 中等 | Longest Consecutive Sequence |
- #39简单#383
Ransom Note
- #40简单#205
Isomorphic Strings
- #41简单#290
Word Pattern
- #42简单#242
Valid Anagram
- #43中等#49站内精讲
Group Anagrams
- #44简单#1站内精讲
Two Sum
- #45简单#202
Happy Number
- #46简单#219
Contains Duplicate II
- #47中等#128站内精讲
Longest Consecutive Sequence
区间
4 题| 顺序 | 难度 | 题目 |
|---|---|---|
| 48 | 简单 | 汇总区间#228 Summary Ranges |
| 49 | 中等 | 合并区间#56 Merge Intervals |
| 50 | 中等 | 插入区间#57 Insert Interval |
| 51 | 中等 | 用最少数量的箭引爆气球#452 Minimum Number of Arrows to Burst Balloons |
- #48简单#228
Summary Ranges
- #49中等#56
Merge Intervals
- #50中等#57
Insert Interval
- #51中等#452
Minimum Number of Arrows to Burst Balloons
栈
5 题| 顺序 | 难度 | 题目 |
|---|---|---|
| 52 | 简单 | Valid Parentheses |
| 53 | 中等 | 简化路径#71 Simplify Path |
| 54 | 中等 | 最小栈#155 Min Stack |
| 55 | 中等 | 逆波兰表达式求值#150 Evaluate Reverse Polish Notation |
| 56 | 困难 | 基本计算器#224 Basic Calculator |
- #52简单#20站内精讲
Valid Parentheses
- #53中等#71
Simplify Path
- #54中等#155
Min Stack
- #55中等#150
Evaluate Reverse Polish Notation
- #56困难#224
Basic Calculator
链表
11 题| 顺序 | 难度 | 题目 |
|---|---|---|
| 57 | 简单 | Linked List Cycle |
| 58 | 中等 | 两数相加#2 Add Two Numbers |
| 59 | 简单 | Merge Two Sorted Lists |
| 60 | 中等 | 随机链表的复制#138 Copy List with Random Pointer |
| 61 | 中等 | 反转链表 II#92 Reverse Linked List II |
| 62 | 困难 | K 个一组翻转链表#25 Reverse Nodes in k-Group |
| 63 | 中等 | Remove Nth Node From End of List |
| 64 | 中等 | Remove Duplicates from Sorted List II |
| 65 | 中等 | 旋转链表#61 Rotate List |
| 66 | 中等 | 分隔链表#86 Partition List |
| 67 | 中等 | LRU 缓存#146 LRU Cache |
- #57简单#141站内精讲
Linked List Cycle
- #58中等#2
Add Two Numbers
- #59简单#21站内精讲
Merge Two Sorted Lists
- #60中等#138
Copy List with Random Pointer
- #61中等#92
Reverse Linked List II
- #62困难#25
Reverse Nodes in k-Group
- #63中等#19
Remove Nth Node From End of List
- #64中等#82
Remove Duplicates from Sorted List II
- #65中等#61
Rotate List
- #66中等#86
Partition List
- #67中等#146
LRU Cache
二叉树
14 题| 顺序 | 难度 | 题目 |
|---|---|---|
| 68 | 简单 | 二叉树的最大深度#104 Maximum Depth of Binary Tree |
| 69 | 简单 | 相同的树#100 Same Tree |
| 70 | 简单 | Invert Binary Tree |
| 71 | 简单 | 对称二叉树#101 Symmetric Tree |
| 72 | 中等 | 从前序与中序遍历序列构造二叉树#105 Construct Binary Tree from Preorder and Inorder Traversal |
| 73 | 中等 | 从中序与后序遍历序列构造二叉树#106 Construct Binary Tree from Inorder and Postorder Traversal |
| 74 | 中等 | Populating Next Right Pointers in Each Node II |
| 75 | 中等 | 二叉树展开为链表#114 Flatten Binary Tree to Linked List |
| 76 | 简单 | 路径总和#112 Path Sum |
| 77 | 中等 | 求根节点到叶节点数字之和#129 Sum Root to Leaf Numbers |
| 78 | 困难 | 二叉树中的最大路径和#124 Binary Tree Maximum Path Sum |
| 79 | 中等 | 二叉搜索树迭代器#173 Binary Search Tree Iterator |
| 80 | 中等 | 完全二叉树的节点个数#222 Count Complete Tree Nodes |
| 81 | 中等 | 二叉树的最近公共祖先#236 Lowest Common Ancestor of a Binary Tree |
- #68简单#104
Maximum Depth of Binary Tree
- #69简单#100
Same Tree
- #70简单#226站内精讲
Invert Binary Tree
- #71简单#101
Symmetric Tree
- #72中等#105
Construct Binary Tree from Preorder and Inorder Traversal
- #73中等#106
Construct Binary Tree from Inorder and Postorder Traversal
- #74中等#117
Populating Next Right Pointers in Each Node II
- #75中等#114
Flatten Binary Tree to Linked List
- #76简单#112
Path Sum
- #77中等#129
Sum Root to Leaf Numbers
- #78困难#124
Binary Tree Maximum Path Sum
- #79中等#173
Binary Search Tree Iterator
- #80中等#222
Count Complete Tree Nodes
- #81中等#236
Lowest Common Ancestor of a Binary Tree
二叉树层次遍历
4 题| 顺序 | 难度 | 题目 |
|---|---|---|
| 82 | 中等 | 二叉树的右视图#199 Binary Tree Right Side View |
| 83 | 简单 | 二叉树的层平均值#637 Average of Levels in Binary Tree |
| 84 | 中等 | 二叉树的层序遍历#102 Binary Tree Level Order Traversal |
| 85 | 中等 | 二叉树的锯齿形层序遍历#103 Binary Tree Zigzag Level Order Traversal |
- #82中等#199
Binary Tree Right Side View
- #83简单#637
Average of Levels in Binary Tree
- #84中等#102
Binary Tree Level Order Traversal
- #85中等#103
Binary Tree Zigzag Level Order Traversal
二叉搜索树
3 题| 顺序 | 难度 | 题目 |
|---|---|---|
| 86 | 简单 | 二叉搜索树的最小绝对差#530 Minimum Absolute Difference in BST |
| 87 | 中等 | 二叉搜索树中第 K 小的元素#230 Kth Smallest Element in a BST |
| 88 | 中等 | 验证二叉搜索树#98 Validate Binary Search Tree |
- #86简单#530
Minimum Absolute Difference in BST
- #87中等#230
Kth Smallest Element in a BST
- #88中等#98
Validate Binary Search Tree
图
6 题| 顺序 | 难度 | 题目 |
|---|---|---|
| 89 | 中等 | 岛屿数量#200 Number of Islands |
| 90 | 中等 | 被围绕的区域#130 Surrounded Regions |
| 91 | 中等 | 克隆图#133 Clone Graph |
| 92 | 中等 | 除法求值#399 Evaluate Division |
| 93 | 中等 | 课程表#207 Course Schedule |
| 94 | 中等 | 课程表 II#210 Course Schedule II |
- #89中等#200
Number of Islands
- #90中等#130
Surrounded Regions
- #91中等#133
Clone Graph
- #92中等#399
Evaluate Division
- #93中等#207
Course Schedule
- #94中等#210
Course Schedule II
图的广度优先搜索
3 题- #95中等#909
Snakes and Ladders
- #96中等#433
Minimum Genetic Mutation
- #97困难#127
Word Ladder
字典树
3 题| 顺序 | 难度 | 题目 |
|---|---|---|
| 98 | 中等 | 实现 Trie (前缀树)#208 Implement Trie (Prefix Tree) |
| 99 | 中等 | 添加与搜索单词 - 数据结构设计#211 Design Add and Search Words Data Structure |
| 100 | 困难 | 单词搜索 II#212 Word Search II |
- #98中等#208
Implement Trie (Prefix Tree)
- #99中等#211
Design Add and Search Words Data Structure
- #100困难#212
Word Search II
回溯
7 题| 顺序 | 难度 | 题目 |
|---|---|---|
| 101 | 中等 | 电话号码的字母组合#17 Letter Combinations of a Phone Number |
| 102 | 中等 | 组合#77 Combinations |
| 103 | 中等 | 全排列#46 Permutations |
| 104 | 中等 | 组合总和#39 Combination Sum |
| 105 | 困难 | N 皇后 II#52 N-Queens II |
| 106 | 中等 | 括号生成#22 Generate Parentheses |
| 107 | 中等 | 单词搜索#79 Word Search |
- #101中等#17
Letter Combinations of a Phone Number
- #102中等#77
Combinations
- #103中等#46
Permutations
- #104中等#39
Combination Sum
- #105困难#52
N-Queens II
- #106中等#22
Generate Parentheses
- #107中等#79
Word Search
分治
4 题| 顺序 | 难度 | 题目 |
|---|---|---|
| 108 | 简单 | 将有序数组转换为二叉搜索树#108 Convert Sorted Array to Binary Search Tree |
| 109 | 中等 | 排序链表#148 Sort List |
| 110 | 中等 | 建立四叉树#427 Construct Quad Tree |
| 111 | 困难 | 合并 K 个升序链表#23 Merge k Sorted Lists |
- #108简单#108
Convert Sorted Array to Binary Search Tree
- #109中等#148
Sort List
- #110中等#427
Construct Quad Tree
- #111困难#23
Merge k Sorted Lists
Kadane 算法
2 题- #112中等#53站内精讲
Maximum Subarray
- #113中等#918
Maximum Sum Circular Subarray
二分查找
7 题| 顺序 | 难度 | 题目 |
|---|---|---|
| 114 | 简单 | 搜索插入位置#35 Search Insert Position |
| 115 | 中等 | 搜索二维矩阵#74 Search a 2D Matrix |
| 116 | 中等 | 寻找峰值#162 Find Peak Element |
| 117 | 中等 | 搜索旋转排序数组#33 Search in Rotated Sorted Array |
| 118 | 中等 | Find First and Last Position of Element in Sorted Array |
| 119 | 中等 | 寻找旋转排序数组中的最小值#153 Find Minimum in Rotated Sorted Array |
| 120 | 困难 | Median of Two Sorted Arrays |
- #114简单#35
Search Insert Position
- #115中等#74
Search a 2D Matrix
- #116中等#162
Find Peak Element
- #117中等#33
Search in Rotated Sorted Array
- #118中等#34
Find First and Last Position of Element in Sorted Array
- #119中等#153
Find Minimum in Rotated Sorted Array
- #120困难#4
Median of Two Sorted Arrays
堆
4 题| 顺序 | 难度 | 题目 |
|---|---|---|
| 121 | 中等 | 数组中的第K个最大元素#215 Kth Largest Element in an Array |
| 122 | 困难 | IPO#502 IPO |
| 123 | 中等 | 查找和最小的 K 对数字#373 Find K Pairs with Smallest Sums |
| 124 | 困难 | 数据流的中位数#295 Find Median from Data Stream |
- #121中等#215
Kth Largest Element in an Array
- #122困难#502
IPO
- #123中等#373
Find K Pairs with Smallest Sums
- #124困难#295
Find Median from Data Stream
位运算
6 题| 顺序 | 难度 | 题目 |
|---|---|---|
| 125 | 简单 | 二进制求和#67 Add Binary |
| 126 | 简单 | 颠倒二进制位#190 Reverse Bits |
| 127 | 简单 | 位1的个数#191 Number of 1 Bits |
| 128 | 简单 | Single Number |
| 129 | 中等 | 只出现一次的数字 II#137 Single Number II |
| 130 | 中等 | 数字范围按位与#201 Bitwise AND of Numbers Range |
- #125简单#67
Add Binary
- #126简单#190
Reverse Bits
- #127简单#191
Number of 1 Bits
- #128简单#136站内精讲
Single Number
- #129中等#137
Single Number II
- #130中等#201
Bitwise AND of Numbers Range
数学
6 题| 顺序 | 难度 | 题目 |
|---|---|---|
| 131 | 简单 | 回文数#9 Palindrome Number |
| 132 | 简单 | 加一#66 Plus One |
| 133 | 中等 | 阶乘后的零#172 Factorial Trailing Zeroes |
| 134 | 简单 | x 的平方根 #69 Sqrt(x) |
| 135 | 中等 | Pow(x, n)#50 Pow(x, n) |
| 136 | 困难 | 直线上最多的点数#149 Max Points on a Line |
- #131简单#9
Palindrome Number
- #132简单#66
Plus One
- #133中等#172
Factorial Trailing Zeroes
- #134简单#69
Sqrt(x)
- #135中等#50
Pow(x, n)
- #136困难#149
Max Points on a Line
一维动态规划
5 题| 顺序 | 难度 | 题目 |
|---|---|---|
| 137 | 简单 | Climbing Stairs |
| 138 | 中等 | 打家劫舍#198 House Robber |
| 139 | 中等 | 单词拆分#139 Word Break |
| 140 | 中等 | 零钱兑换#322 Coin Change |
| 141 | 中等 | 最长递增子序列#300 Longest Increasing Subsequence |
- #137简单#70站内精讲
Climbing Stairs
- #138中等#198
House Robber
- #139中等#139
Word Break
- #140中等#322
Coin Change
- #141中等#300
Longest Increasing Subsequence
多维动态规划
9 题| 顺序 | 难度 | 题目 |
|---|---|---|
| 142 | 中等 | 三角形最小路径和#120 Triangle |
| 143 | 中等 | 最小路径和#64 Minimum Path Sum |
| 144 | 中等 | 不同路径 II#63 Unique Paths II |
| 145 | 中等 | 最长回文子串#5 Longest Palindromic Substring |
| 146 | 中等 | 交错字符串#97 Interleaving String |
| 147 | 中等 | 编辑距离#72 Edit Distance |
| 148 | 困难 | 买卖股票的最佳时机 III#123 Best Time to Buy and Sell Stock III |
| 149 | 困难 | 买卖股票的最佳时机 IV#188 Best Time to Buy and Sell Stock IV |
| 150 | 中等 | 最大正方形#221 Maximal Square |
- #142中等#120
Triangle
- #143中等#64
Minimum Path Sum
- #144中等#63
Unique Paths II
- #145中等#5
Longest Palindromic Substring
- #146中等#97
Interleaving String
- #147中等#72
Edit Distance
- #148困难#123
Best Time to Buy and Sell Stock III
- #149困难#188
Best Time to Buy and Sell Stock IV
- #150中等#221
Maximal Square