跳至主要內容

面试必刷 150 题


数组 / 字符串

题号标题题解标签难度力扣
88合并两个有序数组[✓]数组 双指针 排序🟢🀄️open in new window 🔗open in new window
27移除元素[✓]数组 双指针🟢🀄️open in new window 🔗open in new window
26删除有序数组中的重复项[✓]数组 双指针🟢🀄️open in new window 🔗open in new window
80删除有序数组中的重复项 II[✓]数组 双指针🟠🀄️open in new window 🔗open in new window
169多数元素[✓]数组 哈希表 分治 2+🟢🀄️open in new window 🔗open in new window
189轮转数组[✓]数组 数学 双指针🟠🀄️open in new window 🔗open in new window
121买卖股票的最佳时机[✓]数组 动态规划🟢🀄️open in new window 🔗open in new window
122买卖股票的最佳时机 II[✓]贪心 数组 动态规划🟠🀄️open in new window 🔗open in new window
55跳跃游戏[✓]贪心 数组 动态规划🟠🀄️open in new window 🔗open in new window
45跳跃游戏 II[✓]贪心 数组 动态规划🟠🀄️open in new window 🔗open in new window
274H 指数[✓]数组 计数排序 排序🟠🀄️open in new window 🔗open in new window
380O(1) 时间插入、删除和获取随机元素[✓]设计 数组 哈希表 2+🟠🀄️open in new window 🔗open in new window
238除自身以外数组的乘积[✓]数组 前缀和🟠🀄️open in new window 🔗open in new window
134加油站[✓]贪心 数组🟠🀄️open in new window 🔗open in new window
135分发糖果[✓]贪心 数组🔴🀄️open in new window 🔗open in new window
42接雨水[✓] 数组 双指针 2+🔴🀄️open in new window 🔗open in new window
13罗马数字转整数[✓]哈希表 数学 字符串🟢🀄️open in new window 🔗open in new window
12整数转罗马数字[✓]哈希表 数学 字符串🟠🀄️open in new window 🔗open in new window
58最后一个单词的长度[✓]字符串🟢🀄️open in new window 🔗open in new window
14最长公共前缀[✓]字典树 字符串🟢🀄️open in new window 🔗open in new window
151反转字符串中的单词[✓]双指针 字符串🟠🀄️open in new window 🔗open in new window
6Z 字形变换[✓]字符串🟠🀄️open in new window 🔗open in new window
28找出字符串中第一个匹配项的下标[✓]双指针 字符串 字符串匹配🟢🀄️open in new window 🔗open in new window
68文本左右对齐[✓]数组 字符串 模拟🔴🀄️open in new window 🔗open in new window

双指针

题号标题题解标签难度力扣
125验证回文串[✓]双指针 字符串🟢🀄️open in new window 🔗open in new window
392判断子序列[✓]双指针 字符串 动态规划🟢🀄️open in new window 🔗open in new window
167两数之和 II - 输入有序数组[✓]数组 双指针 二分查找🟠🀄️open in new window 🔗open in new window
11盛最多水的容器[✓]贪心 数组 双指针🟠🀄️open in new window 🔗open in new window
15三数之和[✓]数组 双指针 排序🟠🀄️open in new window 🔗open in new window

滑动窗口

题号标题题解标签难度力扣
209长度最小的子数组[✓]数组 二分查找 前缀和 1+🟠🀄️open in new window 🔗open in new window
3无重复字符的最长子串[✓]哈希表 字符串 滑动窗口🟠🀄️open in new window 🔗open in new window
30串联所有单词的子串[✓]哈希表 字符串 滑动窗口🔴🀄️open in new window 🔗open in new window
76最小覆盖子串[✓]哈希表 字符串 滑动窗口🔴🀄️open in new window 🔗open in new window

矩阵

题号标题题解标签难度力扣
36有效的数独[✓]数组 哈希表 矩阵🟠🀄️open in new window 🔗open in new window
54螺旋矩阵[✓]数组 矩阵 模拟🟠🀄️open in new window 🔗open in new window
48旋转图像[✓]数组 数学 矩阵🟠🀄️open in new window 🔗open in new window
73矩阵置零[✓]数组 哈希表 矩阵🟠🀄️open in new window 🔗open in new window
289生命游戏[✓]数组 矩阵 模拟🟠🀄️open in new window 🔗open in new window

哈希表

题号标题题解标签难度力扣
383赎金信[✓]哈希表 字符串 计数🟢🀄️open in new window 🔗open in new window
205同构字符串[✓]哈希表 字符串🟢🀄️open in new window 🔗open in new window
290单词规律[✓]哈希表 字符串🟢🀄️open in new window 🔗open in new window
242有效的字母异位词[✓]哈希表 字符串 排序🟢🀄️open in new window 🔗open in new window
49字母异位词分组[✓]数组 哈希表 字符串 1+🟠🀄️open in new window 🔗open in new window
1两数之和[✓]数组 哈希表🟢🀄️open in new window 🔗open in new window
202快乐数[✓]哈希表 数学 双指针🟢🀄️open in new window 🔗open in new window
219存在重复元素 II[✓]数组 哈希表 滑动窗口🟢🀄️open in new window 🔗open in new window
128最长连续序列[✓]并查集 数组 哈希表🟠🀄️open in new window 🔗open in new window

间隔

题号标题题解标签难度力扣
228汇总区间[✓]数组🟢🀄️open in new window 🔗open in new window
56合并区间[✓]数组 排序🟠🀄️open in new window 🔗open in new window
57插入区间[✓]数组🟠🀄️open in new window 🔗open in new window
452用最少数量的箭引爆气球[✓]贪心 数组 排序🟠🀄️open in new window 🔗open in new window

题号标题题解标签难度力扣
20有效的括号[✓] 字符串🟢🀄️open in new window 🔗open in new window
71简化路径[✓] 字符串🟠🀄️open in new window 🔗open in new window
155最小栈[✓] 设计🟠🀄️open in new window 🔗open in new window
150逆波兰表达式求值[✓] 数组 数学🟠🀄️open in new window 🔗open in new window
224基本计算器[✓] 递归 数学 1+🔴🀄️open in new window 🔗open in new window

链表

题号标题题解标签难度力扣
141环形链表[✓]哈希表 链表 双指针🟢🀄️open in new window 🔗open in new window
2两数相加[✓]递归 链表 数学🟠🀄️open in new window 🔗open in new window
21合并两个有序链表[✓]递归 链表🟢🀄️open in new window 🔗open in new window
138随机链表的复制[✓]哈希表 链表🟠🀄️open in new window 🔗open in new window
92反转链表 II[✓]链表🟠🀄️open in new window 🔗open in new window
25K 个一组翻转链表[✓]递归 链表🔴🀄️open in new window 🔗open in new window
19删除链表的倒数第 N 个结点[✓]链表 双指针🟠🀄️open in new window 🔗open in new window
82删除排序链表中的重复元素 II[✓]链表 双指针🟠🀄️open in new window 🔗open in new window
61旋转链表[✓]链表 双指针🟠🀄️open in new window 🔗open in new window
86分隔链表[✓]链表 双指针🟠🀄️open in new window 🔗open in new window
146LRU 缓存[✓]设计 哈希表 链表 1+🟠🀄️open in new window 🔗open in new window

  • 二叉树
题号标题题解标签难度力扣
104二叉树的最大深度[✓] 深度优先搜索 广度优先搜索 1+🟢🀄️open in new window 🔗open in new window
100相同的树[✓] 深度优先搜索 广度优先搜索 1+🟢🀄️open in new window 🔗open in new window
226翻转二叉树[✓] 深度优先搜索 广度优先搜索 1+🟢🀄️open in new window 🔗open in new window
101对称二叉树[✓] 深度优先搜索 广度优先搜索 1+🟢🀄️open in new window 🔗open in new window
105从前序与中序遍历序列构造二叉树[✓] 数组 哈希表 2+🟠🀄️open in new window 🔗open in new window
106从中序与后序遍历序列构造二叉树[✓] 数组 哈希表 2+🟠🀄️open in new window 🔗open in new window
117填充每个节点的下一个右侧节点指针 II[✓] 深度优先搜索 广度优先搜索 2+🟠🀄️open in new window 🔗open in new window
114二叉树展开为链表[✓] 深度优先搜索 2+🟠🀄️open in new window 🔗open in new window
112路径总和[✓] 深度优先搜索 广度优先搜索 1+🟢🀄️open in new window 🔗open in new window
129求根节点到叶节点数字之和[✓] 深度优先搜索 二叉树🟠🀄️open in new window 🔗open in new window
124二叉树中的最大路径和[✓] 深度优先搜索 动态规划 1+🔴🀄️open in new window 🔗open in new window
173二叉搜索树迭代器[✓] 设计 3+🟠🀄️open in new window 🔗open in new window
222完全二叉树的节点个数[✓]位运算 二分查找 1+🟢🀄️open in new window 🔗open in new window
236二叉树的最近公共祖先[✓] 深度优先搜索 二叉树🟠🀄️open in new window 🔗open in new window
  • 二叉树的广度优先搜索
题号标题题解标签难度力扣
199二叉树的右视图[✓] 深度优先搜索 广度优先搜索 1+🟠🀄️open in new window 🔗open in new window
637二叉树的层平均值[✓] 深度优先搜索 广度优先搜索 1+🟢🀄️open in new window 🔗open in new window
102二叉树的层序遍历[✓] 广度优先搜索 二叉树🟠🀄️open in new window 🔗open in new window
103二叉树的锯齿形层序遍历[✓] 广度优先搜索 二叉树🟠🀄️open in new window 🔗open in new window
  • 二叉搜索树
题号标题题解标签难度力扣
530二叉搜索树的最小绝对差[✓] 深度优先搜索 广度优先搜索 2+🟢🀄️open in new window 🔗open in new window
230二叉搜索树中第 K 小的元素[✓] 深度优先搜索 二叉搜索树 1+🟠🀄️open in new window 🔗open in new window
98验证二叉搜索树[✓] 深度优先搜索 二叉搜索树 1+🟠🀄️open in new window 🔗open in new window
  • 前缀树
题号标题题解标签难度力扣
208实现 Trie (前缀树)[✓]设计 字典树 哈希表 1+🟠🀄️open in new window 🔗open in new window
211添加与搜索单词 - 数据结构设计[✓]深度优先搜索 设计 字典树 1+🟠🀄️open in new window 🔗open in new window
212单词搜索 II[✓]字典树 数组 字符串 2+🔴🀄️open in new window 🔗open in new window

  • 图的深度优先搜索
题号标题题解标签难度力扣
200岛屿数量[✓]深度优先搜索 广度优先搜索 并查集 2+🟠🀄️open in new window 🔗open in new window
130被围绕的区域[✓]深度优先搜索 广度优先搜索 并查集 2+🟠🀄️open in new window 🔗open in new window
133克隆图[✓]深度优先搜索 广度优先搜索 1+🟠🀄️open in new window 🔗open in new window
399除法求值[✓]深度优先搜索 广度优先搜索 并查集 4+🟠🀄️open in new window 🔗open in new window
207课程表[✓]深度优先搜索 广度优先搜索 1+🟠🀄️open in new window 🔗open in new window
210课程表 II[✓]深度优先搜索 广度优先搜索 1+🟠🀄️open in new window 🔗open in new window
  • 图的广度优先搜索
题号标题题解标签难度力扣
945使数组唯一的最小增量[✓]贪心 数组 计数 1+🟠🀄️open in new window 🔗open in new window
433最小基因变化[✓]广度优先搜索 哈希表 字符串🟠🀄️open in new window 🔗open in new window
127单词接龙[✓]广度优先搜索 哈希表 字符串🔴🀄️open in new window 🔗open in new window

回溯

题号标题题解标签难度力扣
17电话号码的字母组合[✓]哈希表 字符串 回溯🟠🀄️open in new window 🔗open in new window
77组合[✓]回溯🟠🀄️open in new window 🔗open in new window
46全排列[✓]数组 回溯🟠🀄️open in new window 🔗open in new window
39组合总和[✓]数组 回溯🟠🀄️open in new window 🔗open in new window
52N 皇后 II[✓]回溯🔴🀄️open in new window 🔗open in new window
22括号生成[✓]字符串 动态规划 回溯🟠🀄️open in new window 🔗open in new window
79单词搜索[✓]数组 字符串 回溯 1+🟠🀄️open in new window 🔗open in new window

分治

题号标题题解标签难度力扣
108将有序数组转换为二叉搜索树[✓] 二叉搜索树 数组 2+🟢🀄️open in new window 🔗open in new window
148排序链表[✓]链表 双指针 分治 2+🟠🀄️open in new window 🔗open in new window
772基本计算器 III 🔒[✓] 递归 数学 1+🔴🀄️open in new window 🔗open in new window
23合并 K 个升序链表[✓]链表 分治 堆(优先队列) 1+🔴🀄️open in new window 🔗open in new window

二分查找

题号标题题解标签难度力扣
35搜索插入位置[✓]数组 二分查找🟢🀄️open in new window 🔗open in new window
74搜索二维矩阵[✓]数组 二分查找 矩阵🟠🀄️open in new window 🔗open in new window
162寻找峰值[✓]数组 二分查找🟠🀄️open in new window 🔗open in new window
33搜索旋转排序数组[✓]数组 二分查找🟠🀄️open in new window 🔗open in new window
34在排序数组中查找元素的第一个和最后一个位置[✓]数组 二分查找🟠🀄️open in new window 🔗open in new window
153寻找旋转排序数组中的最小值[✓]数组 二分查找🟠🀄️open in new window 🔗open in new window
4寻找两个正序数组的中位数[✓]数组 二分查找 分治🔴🀄️open in new window 🔗open in new window

题号标题题解标签难度力扣
215数组中的第K个最大元素[✓]数组 分治 快速选择 2+🟠🀄️open in new window 🔗open in new window
502IPO[✓]贪心 数组 排序 1+🔴🀄️open in new window 🔗open in new window
373查找和最小的 K 对数字[✓]数组 堆(优先队列)🟠🀄️open in new window 🔗open in new window
295数据流的中位数[✓]设计 双指针 数据流 2+🔴🀄️open in new window 🔗open in new window

位运算

题号标题题解标签难度力扣
67二进制求和[✓]位运算 数学 字符串 1+🟢🀄️open in new window 🔗open in new window
190颠倒二进制位[✓]位运算 分治🟢🀄️open in new window 🔗open in new window
191位1的个数[✓]位运算 分治🟢🀄️open in new window 🔗open in new window
136只出现一次的数字[✓]位运算 数组🟢🀄️open in new window 🔗open in new window
137只出现一次的数字 II[✓]位运算 数组🟠🀄️open in new window 🔗open in new window
201数字范围按位与[✓]位运算🟠🀄️open in new window 🔗open in new window

数学

题号标题题解标签难度力扣
9回文数[✓]数学🟢🀄️open in new window 🔗open in new window
66加一[✓]数组 数学🟢🀄️open in new window 🔗open in new window
172阶乘后的零[✓]数学🟠🀄️open in new window 🔗open in new window
69x 的平方根[✓]数学 二分查找🟢🀄️open in new window 🔗open in new window
50Pow(x, n)[✓]递归 数学🟠🀄️open in new window 🔗open in new window
149直线上最多的点数[✓]几何 数组 哈希表 1+🔴🀄️open in new window 🔗open in new window

动态规划

  • Kadane 算法
题号标题题解标签难度力扣
53最大子数组和[✓]数组 分治 动态规划🟠🀄️open in new window 🔗open in new window
954二倍数对数组[✓]贪心 数组 哈希表 1+🟠🀄️open in new window 🔗open in new window
  • 一维
题号标题题解标签难度力扣
70爬楼梯[✓]记忆化搜索 数学 动态规划🟢🀄️open in new window 🔗open in new window
198打家劫舍[✓]数组 动态规划🟠🀄️open in new window 🔗open in new window
139单词拆分[✓]字典树 记忆化搜索 数组 3+🟠🀄️open in new window 🔗open in new window
322零钱兑换[✓]广度优先搜索 数组 动态规划🟠🀄️open in new window 🔗open in new window
300最长递增子序列[✓]数组 二分查找 动态规划🟠🀄️open in new window 🔗open in new window
  • 多维
题号标题题解标签难度力扣
120三角形最小路径和[✓]数组 动态规划🟠🀄️open in new window 🔗open in new window
64最小路径和[✓]数组 动态规划 矩阵🟠🀄️open in new window 🔗open in new window
63不同路径 II[✓]数组 动态规划 矩阵🟠🀄️open in new window 🔗open in new window
5最长回文子串[✓]双指针 字符串 动态规划🟠🀄️open in new window 🔗open in new window
97交错字符串[✓]字符串 动态规划🟠🀄️open in new window 🔗open in new window
72编辑距离[✓]字符串 动态规划🟠🀄️open in new window 🔗open in new window
123买卖股票的最佳时机 III[✓]数组 动态规划🔴🀄️open in new window 🔗open in new window
188买卖股票的最佳时机 IV[✓]数组 动态规划🔴🀄️open in new window 🔗open in new window
221最大正方形[✓]数组 动态规划 矩阵🟠🀄️open in new window 🔗open in new window