# 精尽数据结构与算法面试题「最新更新时间:2024-02」 > 本文,我们将“数据结构与算法”,直接简称“算法”,更加简洁。实际上,数据结构、算法,是两个相关性很高的不同的知识点。 当胖友准备开始准备算法相关的面试,就要做好心理准备,这可能是比想象中痛苦的过程,并且时间还不短,少则三个月,半年也是比较正常的时间。 不过艿艿觉得,随着现在互联网越来越朝着**精英化**发展,对学历对履历的要求越来越高,大公司甚至部分小公司,也愈发注重基础技术。而基础技术,无非考核两点,编程语言和算法。所以,这个过程,可能真的是我们必须去体验的。 不过换过来思考,算法不会像我们学习的框架或者中间件,有过时一说。也就说,学习一次,终身受众。并且,相比大多数 CRUD 的无脑,撩撩算法,也是一种“放松”,哈哈哈哈。 # 如何学习? 可能很多同学,一说到算法面试的准备,就想到的是去 LeetCode 去刷题?!但是,这个真的正确么?一半一半。相信绝大多数胖友,在大学里是没有认真学习算法,又或者在工作中,因为应用较少,所以基本忘记的也差不多了。 **那么,就必须重新学习下算法!**请不要上来就去 LeetCode 去刷题,简直是花样作死。算法准备,是一场持久战,需要系统的去准备。那么,怎么进行学习呢? 讲真,市面上大多数算法,无论是书籍,还是视频,真的真的真的是看不下去啊看不下去。有握爪的胖友么?最近,刷了王争的 [《数据结构与算法之美》](http://www.iocoder.cn/images/jikeshijian/数据结构与算法之美.jpg) ,哈哈哈,还很认真的做了笔记。如下图: [![笔记](20-精尽数据结构与算法面试题.assets/01.png)](http://www.iocoder.cn/images/Interview/2020-01-04/01.png)笔记 > 艿艿,利益无关,主要是自己看了,真的觉得不错,足够适合我们准备算法面试。如果想要挑战,请去看 [《数据结构与算法分析:Java语言描述》](https://item.jd.com/11886254.html) 等等。呵,等着胖友回来说,“奶奶,我错了~~~😿” 哈哈哈哈。 但是,还是要打个预防针,即使艿艿推荐了 [《数据结构与算法之美》](http://www.iocoder.cn/images/jikeshijian/数据结构与算法之美.jpg) 这个教程,也并不意味着它很简单。它还是非常难的,特别是红黑树!简直是魔鬼啊!!!仅仅是说,它足够能够让艿艿看完,并且蛮多时候在地铁上就能耐心看完。嘻嘻,不过呢,我有 2 年 ACM 集训的经验,可能底子又比大多数同学好点。对于 [《数据结构与算法分析:Java语言描述》](https://item.jd.com/11886254.html) 来说,在地铁上,真的是分分钟趟睡,又或是拿出手机,刷刷刷。 胖友,要拿出勇气!如果碰到困难的,就退缩,就不要准备算法面试,不要想着去大公司。想啥呢!对吧。 # 如何练习? **三分学,七分练**。用在算法面试的准备中,非常适合。哈哈哈,在算法面试的准备中,真正占用时间的是,不是算法的学习,而是在算法的练习中。这个过程,比学习算法会更加痛苦和难受。但是,也只有经历了练习的过程,学习算法,才可能真正变成学会算法。 就好比说,我们学习了数学的某个知识点,直接去考试,绝大数情况下,可能是直接懵逼。同理,切换到真正去公司面试时,考到具体的算法题目,肯定也是类似的情况。所以,一定要勤加练习,死磕练习,玩命练习。 那么,如何练习算法呢?答案很简单,去刷 LeetCode 。比较幸运的是,目前 LeetCode 有国内的版本,可以访问 https://leetcode-cn.com/ 进行愉快的玩耍,照顾我们这些英语不好的孩子。LeetCode 本土化的名字,真的是堪比麦丹劳的“金拱门”,竟然见“力扣”,哈哈哈哈。 不过,怎么刷 LeetCode 呢?毕竟 LeetCode 已经进入**千题**时代,想要全部做完,肯定是不太现实,即使时间允许,我们的实力也不允许,哈哈哈哈。推荐看看 [《花花酱 LeetCode进入千题时代后该如何刷题?》](https://www.bilibili.com/video/av42947553/?p=1) 。可以开倍速播放,比较核心的,就是下面这张图: > [![如何刷题](20-精尽数据结构与算法面试题.assets/02.png)](http://www.iocoder.cn/images/Interview/2020-01-04/02.png)如何刷题 即使如此,可能对于基础相对薄弱的,或者之前没啥刷题经验的胖友,直接上来就刷 LeetCode 题目,特别是一些**困难**级别的题目,可能简直是进了地狱模式的游戏难度,挫败感 120 分的强烈。那么怎么办呢?马化腾爸爸,很早就告诉了我们残酷的真理,“不充钱,怎么变强!”。所以,我们可能需要看一些针对 LeetCode 出的刷题面试**视频**课程: - 覃超 [《算法面试通关 40 讲》](http://www.iocoder.cn/images/jikeshijian/算法面试通关40讲.jpg) - 左神 [《牛客算法系列》](https://www.nowcoder.com/courses) > 貌似不是针对 LeetCode 课程的,主要是牛逼,所以放这里。 - 小象学院 [《面试算法 LeetCode 刷题班》](http://www.chinahadoop.cn/classroom/59/introduction) - 苏勇 [《300 分钟搞定算法面试》](https://kaiwu.lagou.com/course/courseInfo.htm) > 拉钩网和 LeetCode 联合处的课程。 艿艿的话,自己刷的是,覃超 [《算法面试通关 40 讲》](http://www.iocoder.cn/images/jikeshijian/算法面试通关40讲.jpg) 。并且,还是老样子,认真做了笔记,如下图: [![笔记](20-精尽数据结构与算法面试题.assets/03.png)](http://www.iocoder.cn/images/Interview/2020-01-04/03.png)笔记 > 题外话,因为艿艿自己不准备面试,所以一般是不会去看算法。但是考虑到,这篇文章,蛮多人催的,所以自己又看了蛮多的资料的。就冲这份良心,我都给自己打 120 分。 另外,市面上也有一些讲面试算法的书,这里也补充整理下,直接放下面: - 左神 [《程序员代码面试指南:IT 名企算法与数据结构题目最优解(第二版)》](https://item.jd.com/12518392.html) > 豆瓣评分 8.9 分,以面试视角的算法书。 - 何海涛 [《剑指 Offer:名企面试官精讲典型编程题》](https://union-click.jd.com/jdc?d=wnrKQh) > 豆瓣评分 9.1 分,也讲了面试中的算法,同时也介绍了其它的。 - [《编程之美:微软技术面试心得》](https://u.jd.com/wTp20p) > 豆瓣评分 8.3 分,3000 多人评价,还是一本面试相关的算法书籍。主要是,大多数胖友学习算法是为了解决面试,所以就多推荐一点啦。 考虑到大多数胖友,都是在职为主的,可以直接考虑 [《算法面试通关 40 讲》](http://www.iocoder.cn/images/jikeshijian/算法面试通关40讲.jpg) 。主要原因,还是因为我目前暂时只看完了这套教程。后续,我也抽时间看看,左神和小象学院的视频,良心如我。 # 哪些题目? 正如我们在 [《花花酱 LeetCode进入千题时代后该如何刷题?》](https://www.bilibili.com/video/av42947553/?p=1) 看到的视频,我们需要每个类型的 10-20 题,所以我们需要知道,算法面试,主要有哪些**题型**,每个题型刷哪些**题目**。 题型来说,我们可以按照数据结构与算法分别分类: > 整理题型和题库时,按照自己的想法,并且参考下面的资料: > > - [LeetCode](https://leetcode-cn.com/problemset/all/) ,提供了每道题所属的题型,很赞! > - [数据结构与算法之美](http://www.iocoder.cn/images/jikeshijian/数据结构与算法之美.jpg) > - [算法面试通关 40 讲](http://www.iocoder.cn/images/jikeshijian/算法面试通关40讲.jpg) > - [花花酱 LeetCode 题目分类](https://docs.google.com/spreadsheets/d/1SbpY-04Cz8EWw3A_LBUmDEXKUMO31DBjfeMoA0dlfIA/edit#gid=126913158) > - [CS-Notes](https://github.com/CyC2018/CS-Notes/) > - [LeetCode 详解](https://legacy.gitbook.com/book/hk029/leetbook/details) > - [AlgoCasts](https://algocasts.io/episodes) - 数据结构 - 数组 > 矩阵,本质是二维数组。有些文章会喜欢归类成“数组与矩阵”,是一个意思。 - 链表 - 栈和队列 - 字符串 - 哈希表(散列表) - 树 - 堆 - 图 - 算法 - 双指针 - 排序 - 二分查找 - 深度优先搜索 - 广度优先搜索 - 拓扑排序 - 并查集 - 分治算法 - 回溯算法 - 贪心算法 - 动态规划 - 位运算 - 数学 下面,按照这个分类,逐个来看看,需要做哪些题目。 > 友情提示:题目的顺序,主要按照王争老师的 [《数据结构与算法之美》](http://www.iocoder.cn/images/jikeshijian/数据结构与算法之美.jpg) 为主。主要考虑点,是艿艿是按照这个顺序复习的,哈哈哈哈。 > > 注意:每个下面的每个**解答**后面,每个 Solution 类,都对应一个解决方式。另外,一些题目,可能存在**多解**。建议的话,都去理解掉,因为面试官可能刨根问底。 > > 😈 嘿嘿,发现自己撸了快 300 题 leetcode 左右,所以体量还是比较大的。艿艿尽量参考 LeetCode 提供的「🔥热题 HOT 100 」、「精选 TOP 面试题」,进行下标记。 > > 刷题很累,多多坚持! ## 数组 > 【双指针】,一般用于数组的解题中。所以它的题目,我们也会放在【数组】这个题型中,也就是当前小节。通过双指针,可以将一些时间复杂度为 O(N^2) 的解法,进行优化成 O(N) 。 > > 因为把【数组】和【双指针】放在了一起,所以题目可能蛮多的。保持淡定,相比动态规划等题目,这两类算比较简单的。 ### 001. 两数之和 - 题目:https://leetcode-cn.com/problems/two-sum/ - 难度:简单 - 解答:[no0001](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0001) 👉 **相似题目**:167. 两数之和 II - 输入有序数组 - 题目:https://leetcode-cn.com/problems/two-sum-ii-input-array-is-sorted/ - 难度:简单 - 解答:[no0167](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0167) 👉 **相似题目**:015. 三数之和 - 题目:https://leetcode-cn.com/problems/3sum/ - 难度:中等 - 解答:[no0015](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0015) 👉 **相似题目**:016. 最接近的三数之和 - 题目:https://leetcode-cn.com/problems/3sum-closest/ - 难度:中等 - 解答:[no0016](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0016) 👉 **相似题目**:018. 四数之和 - 题目:https://leetcode-cn.com/problems/4sum/ - 难度:中等 - 解答:[no0018](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0018) 👉 **相似题目**:454. 四数相加 II - 题目:https://leetcode-cn.com/problems/4sum/ - 难度:中等 - 解答:[no0454](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0454) 👉 **相似题目**:633. 平方数之和 - 题目:https://leetcode-cn.com/problems/sum-of-square-numbers/ - 难度:简单 - 解答:[no0633](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0633) ### 011. 盛最多水的容器 - 题目:https://leetcode-cn.com/problems/container-with-most-water/ - 难度:中等 - 解答:[no0011](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0011) 👉 **相似题目**:042. 接雨水 - 题目:https://leetcode-cn.com/problems/trapping-rain-water/ - 难度:困难 - 解答:[no0042](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0042) ### 283. 移动零 - 题目:https://leetcode-cn.com/problems/move-zeroes/description/ - 难度:简单 - 解答:[no0283](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0283) 👉 **相似题目**:027. 移除元素 - 题目:https://leetcode-cn.com/problems/remove-element/ - 难度:简单 - 解答:[no0027](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0027) 👉 **相似题目**:026. 删除排序数组中的重复项 - 题目:https://leetcode-cn.com/problems/remove-duplicates-from-sorted-array/ - 难度:简单 - 解答:[no0026](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0026) 👉 **相似题目**:080. 删除排序数组中的重复项 II - 题目:https://leetcode-cn.com/problems/remove-duplicates-from-sorted-array-ii/ - 难度:中等 - 解答:[no0080](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0080) ### 485. 最大连续 1 的个数 - 题目:https://leetcode-cn.com/problems/max-consecutive-ones/ - 难度:简单 - 解答:[no0485](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0485) ### 645. 错误的集合 - 题目:https://leetcode-cn.com/problems/set-mismatch/ - 难度:简单 - 解答:[no0645](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0645) 👉 **相似题目**:448. 找到所有数组中消失的数字 - 题目:https://leetcode-cn.com/problems/find-all-numbers-disappeared-in-an-array/ - 难度:简单 - 解答:[no0448](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0448) 👉 **相似题目**:442. 找到所有数组中消失的数字 - 题目:https://leetcode-cn.com/problems/find-all-duplicates-in-an-array/ - 难度:中等 - 解答:[no0442](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0442) ### 667. 优美的排列 II - 题目:https://leetcode-cn.com/problems/beautiful-arrangement-ii/ - 难度:中等 - 解答:[no0667](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0667) - 备注:找规律,更像一个【数学题】。 ### 697. 数组的度 - 题目:https://leetcode-cn.com/problems/degree-of-an-array/ - 难度:简单 - 解答:[no0697](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0697) ### 565. 嵌套数组 - 题目:https://leetcode-cn.com/problems/array-nesting/ - 难度:中等 - 解答:[no0565](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0565) ### 769. 最多能完成排序的块 - 题目:https://leetcode-cn.com/problems/max-chunks-to-make-sorted/ - 难度:中等 - 解答:[no0769](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0769) - 备注:找规律,更像一个【数学题】。 👉 **相似题目**:768. 最多能完成排序的块 II - 题目:https://leetcode-cn.com/problems/max-chunks-to-make-sorted-ii/ - 难度:困难 - 解答:[no0768](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0768) ### 977. 有序数组的平方 - 题目:https://leetcode-cn.com/problems/squares-of-a-sorted-array/ - 难度:简单 - 解答:[no0997](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0997) ### 118. 杨辉三角 - 题目:https://leetcode-cn.com/problems/pascals-triangle/ - 难度:简单 - 解答:[no0118](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0118) 👉 **相似题目**:119. 杨辉三角 II - 题目:https://leetcode-cn.com/problems/pascals-triangle-ii/ - 难度:简单 - 解答:[no0119](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0119) ### 189. 旋转数组 - 题目:https://leetcode-cn.com/problems/rotate-array/ - 难度:简单 - 解答:[no0189](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0189) ### 238. 除自身以外数组的乘积 - 题目:https://leetcode-cn.com/problems/product-of-array-except-self/ - 难度:中等 - 解答:[no0238](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0238) ## 矩阵 ### 766. 托普利茨矩阵 - 题目:https://leetcode-cn.com/problems/toeplitz-matrix/ - 难度:简单 - 解答:[no0766](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0766) ### 566. 重塑矩阵 - 题目:https://leetcode-cn.com/problems/reshape-the-matrix/ - 难度:简单 - 解答:[no0566](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0566) ### 074. 搜索二维矩阵 - 题目:https://leetcode-cn.com/problems/search-a-2d-matrix/ - 难度:中等 - 解答:[no0074](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0074) ### 240. 搜索二维矩阵 II - 题目:https://leetcode-cn.com/problems/search-a-2d-matrix-ii/ - 难度:中等 - 解答:[no0240](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0240) ### 054. 螺旋矩阵 - 题目:https://leetcode-cn.com/problems/spiral-matrix/ - 难度:中等 - 解答:[no0054](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0054) ### 073. 矩阵置零 - 题目:https://leetcode-cn.com/problems/set-matrix-zeroes/ - 难度:中等 - 解答:[no0073](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0073) ## 字符串 ### 028. 实现 strStr() - 题目:https://leetcode-cn.com/problems/implement-strstr/ - 难度:简单 - 解答:[no0028](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0028) ### 242. 有效的字母异位词 - 题目:https://leetcode-cn.com/problems/valid-anagram/ - 难度:简单 - 解答:[no0242](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0242) 👉 **相似题目**:049. 字母异位词分组 - 题目:https://leetcode-cn.com/problems/group-anagrams/ - 难度:中等 - 解答:[no0049](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0049) ### 205. 字符串同构 - 题目:https://leetcode-cn.com/problems/isomorphic-strings/ - 难度:简单 - 解答:[no0205](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0205) ### 125. 验证回文串 - 题目:https://leetcode-cn.com/problems/valid-palindrome/ - 难度:简单 - 解答:[no0125](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0125) 👉 **相似题目**:680. 验证回文字符串 Ⅱ - 题目:https://leetcode-cn.com/problems/valid-palindrome-ii/ - 难度:简单 - 解答:[no0680](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0680) 👉 **相似题目**:409. 最长回文串 - 题目:https://leetcode-cn.com/problems/longest-palindrome/ - 难度:简单 - 解答:[no0409](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0409) 👉 **相似题目**:009. 判断一个整数是否是回文数 - 题目:https://leetcode-cn.com/problems/palindrome-number/ - 难度:简单 - 解答:[no0009](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0009) ### 344. 反转字符串 - 题目:https://leetcode-cn.com/problems/reverse-string/ - 难度:简单 - 解答:[no0344](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0344) 👉 **相似题目**:345. 反转字符串中的元音字母 > 艿艿:这道题目,刚一看,一脸懵逼。可以简单理解成,需要将元音字母之间,做兑换。例如说,第一个元音字符和倒数一个元音字符对换,第二个原因字符和倒数第二个元音字符对换。而元音字母是 `aeiouAEIOU` 。 - 题目:https://leetcode-cn.com/problems/reverse-vowels-of-a-string/ - 难度:简单 - 解答:[no0345](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0345) ### 524. 通过删除字母匹配到字典里最长单词 - 题目:https://leetcode-cn.com/problems/longest-word-in-dictionary-through-deleting/ - 难度:中等 - 解答:[no0524](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0524) ### 003. 无重复字符的最长子串 - 题目:https://leetcode-cn.com/problems/longest-substring-without-repeating-characters/ - 难度:中等 - 解答:[no0003](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0003) > 基于滑动窗口实现 👉 **相似题目**:159. 至多包含两个不同字符的最长子串 - 题目:https://leetcode-cn.com/problems/longest-substring-with-at-most-two-distinct-characters/ - 难度:困难 - 解答:[no0159](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0159) 👉 **相似题目**:340. 至多包含两个不同字符的最长子串 - 题目:https://leetcode-cn.com/problems/longest-substring-with-at-most-k-distinct-characters/ - 难度:困难 - 解答:[no0340](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0340) ### 696. 计数二进制子串 - 题目:https://leetcode-cn.com/problems/count-binary-substrings/ - 难度:简单 - 解答:[no0696](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0696) ### 151. 翻转字符串里的单词 - 题目:https://leetcode-cn.com/problems/reverse-words-in-a-string/ - 难度:中等 - 解答:[no0151](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0151) 👉 **相似题目**:557. 反转字符串中的单词 III - 题目:https://leetcode-cn.com/problems/reverse-words-in-a-string-iii/ - 难度:简单 - 解答:[no0557](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0557) ### 008. 字符串转换整数 (atoi) - 题目:https://leetcode-cn.com/problems/string-to-integer-atoi/ - 难度:中等 - 解答:[no0008](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0008) ## 链表 > 每次写链表,都蛮头疼的。如果在搭配上递归的方式,简直就是一脸懵逼。 > > 往往链表的答案不复杂,就是懵逼啊懵逼。 ### 707. 设计链表 - 题目:https://leetcode-cn.com/problems/design-linked-list/ - 难度:简单 - 解答:[no0707](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0707) > 我猜测,一次通过的胖友,基本没有,嘿嘿,虽然是个简单题。 ### 002. 两数相加 - 题目:https://leetcode-cn.com/problems/add-two-numbers/ - 难度:简单 - 解答:[no0002](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0002) 👉 **相似题目**:445. 两数相加 II - 题目:https://leetcode-cn.com/problems/add-two-numbers-ii/ - 难度:中等 - 解答:[no0445](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0445) ### 024. 两两交换链表中的节点 - 题目:https://leetcode-cn.com/problems/swap-nodes-in-pairs/ - 难度:中等 - 解答:[no0024](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0024) > 注意点,交换时,不仅仅要考虑交换的两个节点,还要考虑,之前的节点,指向新的节点。 👉 **相似题目**:234. 回文链表 - 题目:https://leetcode-cn.com/problems/palindrome-linked-list/ - 难度:简单 - 解答:[no0234](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0234) 👉 **相似题目**:206. 反转链表 - 题目:https://leetcode-cn.com/problems/reverse-linked-list/ - 难度:简单 - 解答:[no0206](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0206) 👉 **相似题目**:092. 反转链表 II - 题目:https://leetcode-cn.com/problems/reverse-linked-list-ii/ - 难度:中等 - 解答:[no0092](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0092) 👉 **相似题目**:025. K 个一组翻转链表 - 题目:https://leetcode-cn.com/problems/reverse-nodes-in-k-group/ - 难度:困难 - 解答:[no0025](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0025) 👉 **相似题目** 061. 旋转链表 - 题目:https://leetcode-cn.com/problems/rotate-list/ - 难度:中等 - 解答:[no0061](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0061) ### 083. 删除排序链表中的重复元素 - 题目:https://leetcode-cn.com/problems/remove-duplicates-from-sorted-list/ - 难度:简单 - 解答:[no0083](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0083) 👉 **相似题目**:082. 删除排序链表中的重复元素 II - 题目:https://leetcode-cn.com/problems/remove-duplicates-from-sorted-list-ii/ - 难度:中等 - 解答:[no0082](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0082) ### 160. 相交链表 - 题目:https://leetcode-cn.com/problems/intersection-of-two-linked-lists/ - 难度:简单 - 解答:[no0160](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0160) 👉 **相似题目**:141. 环形链表 - 题目:https://leetcode-cn.com/problems/linked-list-cycle/ - 难度:简单 - 解答:[no0141](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0141) 👉 **相似题目**:142. 环形链表 II - 题目:https://leetcode-cn.com/problems/max-chunks-to-make-sorted-ii/ - 难度:中等 - 解答:[no0142](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0142) ### 148. 排序链表 - 题目:https://leetcode-cn.com/problems/sort-list/ - 难度:中等 - 解答:[no0148](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0148) 👉 **相似题目**:147. 对链表进行插入排序 - 题目:https://leetcode-cn.com/problems/insertion-sort-list/ - 难度:中等 - 解答:[no0147](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0147) ### 021. 合并两个有序链表 - 题目:https://leetcode-cn.com/problems/merge-k-sorted-lists/ - 难度:简单 - 解答:[no0021](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0021) 👉 **相似题目**:023. 合并K个排序链表 - 题目:https://leetcode-cn.com/problems/merge-k-sorted-lists/ - 难度:困难 - 解答:[no0023](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0023) ### 725. 分隔链表 - 题目:https://leetcode-cn.com/problems/split-linked-list-in-parts/ - 难度:中等 - 解答:[no0725](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0725) 👉 **相似题目**:328. 奇偶链表 - 题目:https://leetcode-cn.com/problems/merge-k-sorted-lists/ - 难度:困难 - 解答:[no0023](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0023) ### 725. 分隔链表 - 题目:https://leetcode-cn.com/problems/split-linked-list-in-parts/ - 难度:中等 - 解答:[no0725](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0725) ### 086. 分隔链表 - 题目:https://leetcode-cn.com/problems/partition-list/ - 难度:中等 - 解答:[no0086](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0086) ## 二分查找 > 艿艿:其实我们已经在前面做了一堆二分查找的题目,嘿嘿。 > > 当然,本小节,我们会看到很多略微变种的二分查找。 ### 287. 寻找重复数 - 题目:https://leetcode-cn.com/problems/find-the-duplicate-number/ - 难度:中等 - 解答:[no0287](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0287) - 备注:有三种解答,不同时间复杂度,胖友要注意看。 - 最佳解是,经典的**弗洛伊德的乌龟和兔子(循环检测)**。🙂 可能看弗洛伊德的乌龟和兔子,整个推导的过程比较懵逼,耐心。 ### 035. 搜索插入位置 - 题目:https://leetcode-cn.com/problems/search-insert-position/ - 难度:简单 - 解答:[no0035](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0035) 👉 **相似题目**:744. 寻找比目标字母大的最小字母 - 题目:https://leetcode-cn.com/problems/search-insert-position/ - 难度:简单 - 解答:[no0744](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0744) 👉 **相似题目**:034. 在排序数组中查找元素的第一个和最后一个位置 - 题目:https://leetcode-cn.com/problems/find-first-and-last-position-of-element-in-sorted-array/ - 难度:中等 - 解答:[no0034](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0034) 👉 **相似题目**:704. 二分查找 - 题目:https://leetcode-cn.com/problems/binary-search/solution/er-fen-cha-zhao-xiang-jie-by-labuladong/ - 难度:简单 - 解答:[no0704](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0704) 👉 **相似题目**:981. 基于时间的键值存储 - 题目:https://leetcode-cn.com/problems/time-based-key-value-store/ - 难度:中等 - 解答:[no0981](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0981) 👉 **相似题目**:278. 第一个错误的版本 - 题目:https://leetcode-cn.com/problems/first-bad-version/ - 难度:简单 - 解答:[no0278](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0278) ### 153. 寻找旋转排序数组中的最小值 - 题目:https://leetcode-cn.com/problems/find-minimum-in-rotated-sorted-array/ - 难度:中等 - 解答:[no0153](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0153) 👉 **相似题目**:154. 搜索旋转排序数组 - 题目:https://leetcode-cn.com/problems/search-in-rotated-sorted-array/ - 难度:困难 - 解答:[no0154](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0154) 👉 **相似题目**:033. 搜索旋转排序数组 - 题目:https://leetcode-cn.com/problems/search-in-rotated-sorted-array/ - 难度:中等 - 解答:[no0033](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0033) 👉 **相似题目**:081. 搜索旋转排序数组 II - 题目:https://leetcode-cn.com/problems/search-in-rotated-sorted-array-ii/ - 难度:中等 > 假设 154 是困难,那么这题,应该也是困难… - 解答:[no0081](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0081) ### 852. 山脉数组的峰顶索引 - 题目:https://leetcode-cn.com/problems/peak-index-in-a-mountain-array/ - 难度:简单 - 解答:[no0852](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0852) 👉 **相似题目**:162. 寻找峰值 - 题目:https://leetcode-cn.com/problems/find-peak-element/ - 难度:中等 - 解答:[no0162](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0162) ### 069. x 的平方根 - 题目:https://leetcode-cn.com/problems/sqrtx/ - 难度:简单 - 解答:[no0069](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0069) 👉 **相似题目**:367. 有效的完全平方数 - 题目:https://leetcode-cn.com/problems/powx-n/ - 难度:简单 - 解答:[no0367](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0367) 👉 **相似题目**:540. 有序数组中的单一元素 - 题目:https://leetcode-cn.com/problems/single-element-in-a-sorted-array/ - 难度:中等 - 解答:[no0540](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0540) ## 栈和队列 > 这个小节里,我们把「滑动窗口」,也归类在这里。未来,可能会拆分出去。 ### 232. 用队列实现栈 - 题目:https://leetcode-cn.com/problems/implement-queue-using-stacks/ - 难度:简单 - 解答:[no0232](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0232) 👉 **相似题目**:225. 用队列实现栈 - 题目:https://leetcode-cn.com/problems/implement-stack-using-queues/ - 难度:简单 - 解答:[no0225](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0225) ### 155. 最小栈 - 题目:https://leetcode-cn.com/problems/min-stack/ - 难度:简单 - 解答:[no0155](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0155) 👉 **相似题目**:716. 最大栈 - 题目:https://leetcode-cn.com/problems/max-stack/ - 难度:简单 - 解答:[no0716](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0716) ### 020. 有效的括号 - 题目:https://leetcode-cn.com/problems/valid-parentheses/ - 难度:简单 - 解答:[no0020](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0020) 👉 **相似题目**:1003. 检查替换后的词是否有效 - 题目:https://leetcode-cn.com/problems/check-if-word-is-valid-after-substitutions/ - 难度:中等 - 解答:[no1003](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no1003) ### 496. 下一个更大元素 I - 题目:https://leetcode-cn.com/problems/next-greater-element-i/ - 难度:简单 - 解答:[no0496](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0496) 👉 **相似题目**:503. 下一个更大元素 II - 题目:https://leetcode-cn.com/problems/next-greater-element-ii/ - 难度:中等 - 解答:[no0503](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0503) 👉 **相似题目**:739. 每日温度 - 题目:https://leetcode-cn.com/problems/daily-temperatures/ - 难度:中等 - 解答:[no0739](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0739) 👉 **相似题目**:239. 滑动窗口最大值 - 题目:https://leetcode-cn.com/problems/sliding-window-maximum/ - 难度:困难 - 解答:[no0239](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0239) 👉 **相似题目**:076. 最小覆盖子串 - 题目:https://leetcode-cn.com/problems/minimum-window-substring/ - 难度:困难 - 解答:[no0076](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0076) 👉 **相似题目**:438. 找到字符串中所有字母异位词 - 题目:https://leetcode-cn.com/problems/find-all-anagrams-in-a-string/ - 难度:简单 - 解答:[no0438](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0438) ## 递归 ### 856. 括号的分数 - 题目:https://leetcode-cn.com/problems/score-of-parentheses/ - 难度:中等 - 解答:[no0856](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0856) ### 394. 字符串解码 - 题目:https://leetcode-cn.com/problems/decode-string/ - 难度:中等 - 解答:[no0394](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0394) 👉 **相似题目**:726. 原子的数量 - 题目:https://leetcode-cn.com/problems/number-of-atoms/ - 难度:困难 - 解答:[no0726](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0726) ## 排序 ### 215. 数组中的第 K 个最大元素 - 题目:https://leetcode-cn.com/problems/kth-largest-element-in-an-array/ - 难度:中等 - 解答: no0215 - 堆排序 - 快速排序 ### 347. 前 K 个高频元素 - 题目:https://leetcode-cn.com/problems/top-k-frequent-elements/ - 难度:中等 - 解答: no0347 - 计数排序 + 快速排序 👉 **相似题目**:451. 根据字符出现频率排序 - 题目:https://leetcode-cn.com/problems/sort-characters-by-frequency/ - 难度:中等 - 解答:[no0415](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0415) ### 075. 颜色分类 - 题目:https://leetcode-cn.com/problems/sort-colors/ - 难度:中等 - 解答:[no0075](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0075) ## 哈希表 ### 217. 存在重复元素 - 题目:https://leetcode-cn.com/problems/contains-duplicate/ - 难度:简单 - 解答:[no0217](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0217) 👉 **相似题目**:219. 存在重复元素 II - 题目:https://leetcode-cn.com/problems/contains-duplicate-ii/ - 难度:简单 - 解答:[no0219](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0219) 👉 **相似题目**:220. 存在重复元素 III - 题目:https://leetcode-cn.com/problems/contains-duplicate-iii/ - 难度:中等 - 解答: no0220 - 平衡二叉树 - 桶排序,😈 可以通过这个题目练习下。 ### 594. 最长和谐子序列 - 题目:https://leetcode-cn.com/problems/longest-harmonious-subsequence/ - 难度:简单 - 解答:[no0594](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0594) ### 128. 最长连续序列 - 题目:https://leetcode-cn.com/problems/longest-consecutive-sequence/ - 难度:困难 - 解答:[no0128](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0128) ### 387. 字符串中的第一个唯一字符 - 题目:https://leetcode-cn.com/problems/first-unique-character-in-a-string/ - 难度:简单 - 解答:[no0387](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0387) ## 树 > 本小节,题目蛮多的,淡定。 > > 另外,会包括一些二叉搜索树的题目,主要考虑相似题。 ### 104. 二叉树的最大深度 - 题目:https://leetcode-cn.com/problems/maximum-depth-of-binary-tree/ - 难度:简单 - 解答:[no0104](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0104) 👉 **相似题目**:111. 二叉树的最小深度 - 题目:https://leetcode-cn.com/problems/minimum-depth-of-binary-tree/ - 难度:简单 - 解答:[no0111](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0111) 👉 **相似题目**:110. 平衡二叉树 - 题目:https://leetcode-cn.com/problems/balanced-binary-tree/ - 难度:简单 - 解答:[no0110](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0110) 👉 **相似题目**:543. 两节点的最长路径 - 题目:https://leetcode.com/problems/diameter-of-binary-tree/ - 难度:简单 - 解答:[no0543](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0543) ### 112. 路径总和 - 题目:https://leetcode-cn.com/problems/path-sum/ - 难度:简单 - 解答:[no0112](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0112) 👉 **相似题目**:113. 路径总和 II - 题目:https://leetcode-cn.com/problems/path-sum-ii/ - 难度:中等 - 解答:[no0113](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0113) 👉 **相似题目**:437. 路径总和 III - 题目:https://leetcode-cn.com/problems/path-sum-iii/ - 难度:简单 - 解答:[no0437](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0437) 👉 **相似题目**:666. 路径总和 IIII - 题目:https://leetcode-cn.com/problems/path-sum-iiii/ - 难度:简单 - 解答:[no0666](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0666) 👉 **相似题目**:687. 最长同值路径 - 题目:https://leetcode-cn.com/problems/longest-univalue-path/ - 难度:简单 - 解答:[no0687](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0687) 👉 **相似题目**:二叉树的所有路径 - 题目:https://leetcode-cn.com/problems/binary-tree-paths/ - 难度:简单 - 解答:[no0257](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0257) 👉 **相似题目**:129. 求根到叶子节点数字之和 - 题目:https://leetcode-cn.com/problems/binary-tree-maximum-path-sum/ - 难度:中等 - 解答:[no0129](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0129) 👉 **相似题目**:124. 二叉树中的最大路径和 - 题目:https://leetcode-cn.com/problems/sum-root-to-leaf-numbers/ - 难度:困难 - 解答:[no0124](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0124) 👉 **相似题目**:508. 出现次数最多的子树元素和 - 题目:https://leetcode-cn.com/problems/most-frequent-subtree-sum/%3E - 难度:中等 - 解答:[no0508](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0508) ### 226. 翻转二叉树 - 题目:https://leetcode-cn.com/problems/invert-binary-tree/ - 难度:简单 - 解答:[no0226](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0226) ### 617. 合并二叉树 - 题目:https://leetcode-cn.com/problems/merge-two-binary-trees/ - 难度:简单 - 解答:[no0617](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0617) ### 572. 另一个树的子树 - 题目:https://leetcode-cn.com/problems/subtree-of-another-tree/ - 难度:简单 - 解答:[no0572](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0572) 👉 **相似题目**:100. 相同的树 - 题目:https://leetcode-cn.com/problems/same-tree/ - 难度:简单 - 解答:[no0100](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0100) 👉 **相似题目**:965. 单值二叉树 - 题目:https://leetcode-cn.com/problems/univalued-binary-tree/ - 难度:简单 - 解答:[no0965](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0965) 👉 **相似题目**:872. 叶子相似的树 - 题目:https://leetcode-cn.com/problems/leaf-similar-trees/ - 难度:简单 - 解答:[no0872](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0872) 👉 **相似题目**:101. 对称二叉树 - 题目:https://leetcode-cn.com/problems/symmetric-tree/ - 难度:简单 - 解答:[no0101](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0101) ### 337. 打家劫舍 III - 题目:https://leetcode-cn.com/problems/house-robber-iii/ - 难度:中等 - 解答: no0337 - 暴力 DFS 递归 - 经典的树状动态规划 ### 671. 二叉树中第二小的节点 - 题目:https://leetcode-cn.com/problems/second-minimum-node-in-a-binary-tree/ - 难度:简单 - 解答:[no0671](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0671) 👉 **相似题目**:230. 二叉搜索树中第K小的元素 - 题目:https://leetcode-cn.com/problems/kth-smallest-element-in-a-bst/ - 难度:中等 - 解答:[no0230](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0230) ### 637. 二叉树的层平均值 - 题目:https://leetcode-cn.com/problems/average-of-levels-in-binary-tree/ - 难度:简单 - 解答:[no0637](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0637) 👉 **相似题目**:102. 二叉树的层次遍历 - 题目:https://leetcode-cn.com/problems/binary-tree-level-order-traversal/ - 难度:中等 - 解答:[no0102](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0102) 👉 **相似题目**:107. 二叉树的层次遍历 II - 题目:https://leetcode-cn.com/problems/binary-tree-level-order-traversal-ii/ - 难度:简单 - 解答:[no0107](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0107) ### 517. 找树左下角的值 - 题目:https://leetcode-cn.com/problems/find-bottom-left-tree-value/ - 难度:简单 - 解答:[no0517](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0517) ### 144. 二叉树的前序遍历 - 题目:https://leetcode-cn.com/problems/find-bottom-left-tree-value/ - 难度:中等 - 解答:[no0144](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0144) 👉 **相似题目**:094. 二叉树的中序遍历 - 题目:https://leetcode-cn.com/problems/binary-tree-inorder-traversal/ - 难度:中等 - 解答:[no0094](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0094) 👉 **相似题目**:145. 二叉树的后序遍历 - 题目:https://leetcode-cn.com/problems/binary-tree-postorder-traversal/ - 难度:困难 - 解答:[no0145](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0145) 👉 **相似题目**:589. N 叉树的前序遍历 - 题目:https://leetcode-cn.com/problems/n-ary-tree-preorder-traversal/ - 难度:简单 - 解答:[no0589](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0589) 👉 **相似题目**:429. N 叉树的层序遍历 - 题目:https://leetcode-cn.com/problems/n-ary-tree-level-order-traversal/ - 难度:简单 - 解答:[no0429](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0429) 👉 **相似题目**:590. N 叉树的后序遍历 - 题目:https://leetcode-cn.com/problems/n-ary-tree-postorder-traversal/ - 难度:简单 - 解答:[no0590](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0590) 👉 **相似题目**:987. 二叉树的垂序遍历 - 题目:https://leetcode-cn.com/problems/vertical-order-traversal-of-a-binary-tree/ - 难度:中等 - 解答:[no0987](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0987) ### 297. 二叉树的序列化与反序列化 - 题目:https://leetcode-cn.com/problems/serialize-and-deserialize-binary-tree/ - 难度:困难 - 解答:[no0297](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0297) 👉 **相似题目**:449. 序列化和反序列化二叉搜索树 - 题目:https://leetcode-cn.com/problems/serialize-and-deserialize-bst/ - 难度:中等 - 解答:[no0449](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0449) ### 236. 二叉树的最近公共祖先 - 题目:https://leetcode-cn.com/problems/lowest-common-ancestor-of-a-binary-tree/ - 难度:中等 - 解答:[no0236](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0236) 👉 **相似题目**:235. 二叉搜索树的最近公共祖先 - 题目:https://leetcode-cn.com/problems/lowest-common-ancestor-of-a-binary-search-tree/ - 难度:简单 - 解答:[no0235](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0235) ### 814. 二叉树剪枝 - 题目:https://leetcode-cn.com/problems/binary-tree-pruning/ - 难度:简单 - 解答:[no0814](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0814) ## 二叉搜索树 ### 501. 二叉搜索树中的众数 - 题目:https://leetcode-cn.com/problems/find-mode-in-binary-search-tree/ - 难度:简单 - 解答:[no0501](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0501) 👉 **相似题目**:098. 验证二叉搜索树 - 题目:https://leetcode-cn.com/problems/validate-binary-search-tree/ - 难度:中等 - 解答:[no0098](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0098) 👉 **相似题目**:530. 二叉搜索树的最小绝对差 - 题目:https://leetcode-cn.com/problems/minimum-absolute-difference-in-bst/ - 难度:简单 - 解答:[no0530](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0530) 👉 **相似题目**:538. 把二叉搜索树转换为累加树 - 题目:https://leetcode-cn.com/problems/convert-bst-to-greater-tree/ - 难度:简单 - 解答:[no0538](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0538) 👉 **相似题目**:653. 两数之和 IV - 输入 BST - 题目:https://leetcode-cn.com/problems/two-sum-iv-input-is-a-bst/ - 难度:简单 - 解答:[no0653](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0653) ### 108. 将有序数组转换为二叉搜索树 - 题目:https://leetcode-cn.com/problems/convert-sorted-array-to-binary-search-tree/ - 难度:简单 - 解答:[no0108](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0108) 👉 **相似题目**:109. 有序链表转换二叉搜索树 - 题目:https://leetcode-cn.com/problems/convert-sorted-list-to-binary-search-tree/ - 难度:中等 - 解答:[no0109](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0109) ### 700. 二叉搜索树中的搜索 - 题目:https://leetcode-cn.com/problems/search-in-a-binary-search-tree/ - 难度:简单 - 解答:[no0700](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0700) 👉 **相似题目**:701. 二叉搜索树中的插入操作 - 题目:https://leetcode-cn.com/problems/insert-into-a-binary-search-tree/ - 难度:中等 - 解答:[no0701](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0701) 👉 **相似题目**:450. 删除二叉搜索树中的节点 - 题目:https://leetcode-cn.com/problems/delete-node-in-a-bst/ - 难度:中等 - 解答:[no0450](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0450) 👉 **相似题目**:776. 拆分二叉搜索树 - 题目:https://leetcode-cn.com/problems/split-bst/ - 难度:中等 - 解答:[no0776](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0776) 👉 **相似题目**:669. 修剪二叉搜索树 - 题目:https://leetcode-cn.com/problems/trim-a-binary-search-tree/ - 难度:简单 - 解答:[no0669](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0669) ### 099. 恢复二叉搜索树 - 题目:https://leetcode-cn.com/problems/recover-binary-search-tree/ - 难度:困难 - 解答:[no0099](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0099) ## 字典树 ### 208. 实现 Trie (前缀树) - 题目:https://leetcode-cn.com/problems/implement-trie-prefix-tree/ - 难度:中等 - 解答:[no0208](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0208) 👉 **相似题目**:键值映射 - 题目:https://leetcode-cn.com/problems/map-sum-pairs/ - 难度:中等 - 解答:[no0677](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0667) ## BFS && DFS > 考虑到很多题目,既可以用广度优先搜索,也可以使用深度优先搜索。所以,放在一个小节。 ### 785. 判断二分图 - 题目:https://leetcode-cn.com/problems/is-graph-bipartite/ - 难度:中等 - 解答:[no0785](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0785) ### 133. 克隆图 - 题目:https://leetcode-cn.com/problems/clone-graph/ - 难度:中等 - 解答:[no0133](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0133) 👉 **相似题目**:138. 复制带随机指针的链表 - 题目:https://leetcode-cn.com/problems/copy-list-with-random-pointer/ - 难度:中等 - 解答:[no0138](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0138) ### 733. 图像渲染 - 题目:https://leetcode-cn.com/problems/flood-fill/ - 难度:简单 - 解答:[no0733](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0733) 👉 **相似题目**:827. 最大人工岛 - 题目:https://leetcode-cn.com/problems/making-a-large-island/ - 难度:困难 - 解答:[no0827](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0827) ### 279. 完全平方数 - 题目:https://leetcode-cn.com/problems/perfect-squares/ - 难度:中等 - 解答:[no0279](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0279) ### 127. 单词接龙 - 题目:https://leetcode-cn.com/problems/word-ladder/ - 难度:中等 - 解答:[no0127](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0127) 👉 **相似题目**:126. 单词接龙 II - 题目:https://leetcode-cn.com/problems/word-ladder-ii/ - 难度:困难 - 解答:[no0126](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0126) 👉 **相似题目**:433. 最小基因变化 - 题目:https://leetcode-cn.com/problems/minimum-genetic-mutation/ - 难度:中等 - 解答:[no0433](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0433) 👉 **相似题目**:752. 打开转盘锁 - 题目:https://leetcode-cn.com/problems/open-the-lock/ - 难度:中等 - 解答:[no0752](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0752) ### 695. 岛屿的最大面积 - 题目:https://leetcode-cn.com/problems/max-area-of-island/ - 难度:中等 - 解答:[no0695](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0695) 👉 **相似题目**:200. 岛屿数量 - 题目:https://leetcode-cn.com/problems/number-of-islands/ - 难度:中等 - 解答:[no0200](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0200) 👉 **相似题目**:130. 被围绕的区域 - 题目:https://leetcode-cn.com/problems/surrounded-regions/ - 难度:中等 - 解答:[no0130](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0130) ### 547. 朋友圈 - 题目:https://leetcode-cn.com/problems/friend-circles/ - 难度:中等 - 解答:[no0547](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0547) ### 417. 太平洋大西洋水流问题 - 题目:https://leetcode-cn.com/problems/pacific-atlantic-water-flow/ - 难度:中等 - 解答:[no0417](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0417) ### 841. 钥匙和房间 - 题目:https://leetcode-cn.com/problems/keys-and-rooms/ - 难度:中等 - 解答:[no0841](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0841) ### 542. 01 矩阵 - 题目:https://leetcode-cn.com/problems/01-matrix/ - 难度:中等 - 解答:[no0542](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0542) 👉 **相似题目**:934. 最短的桥 - 题目:https://leetcode-cn.com/problems/shortest-bridge/ - 难度:中等 - 解答:[no0934](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0934) 👉 **相似题目**:675. 为高尔夫比赛砍树 - 题目:https://leetcode-cn.com/problems/cut-off-trees-for-golf-event/ - 难度:中等 - 解答:[no0675](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0675) ## 并查集 > 实际上,并查集的题目,是可以使用 BFS 和 DFS 进行实现的,所以本小节题目不会放很多。很多题目,我们在 [「BFS && DFS」](https://svip.iocoder.cn/Data-Structures-and-Algorithms/Interview/#) 小节,顺手去写了下。 ### 684. 冗余连接 - 题目:https://leetcode-cn.com/problems/redundant-connection/ - 难度:中等 - 解答:[no0684](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0684) ## 拓扑排序 ### 207. 课程表 - 题目:https://leetcode-cn.com/problems/course-schedule/ - 难度:中等 - 解答:[no0207](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0207) 👉 **相似题目**:210. 课程表 II - 题目:https://leetcode-cn.com/problems/course-schedule-ii/ - 难度:中等 - 解答:[no0210](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0210) ### 802. 找到最终的安全状态 - 题目:https://leetcode-cn.com/problems/find-eventual-safe-states/ - 难度:中等 - 解答:[no0802](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0802) ## 回溯算法 > 我们会发现,很多回溯算法,是使用 DFS 进行实现。回溯算法是一种思想,常常使用 DFS 算法的方式,进行实现。 ### 017. 电话号码的字母组合 - 题目:https://leetcode-cn.com/problems/letter-combinations-of-a-phone-number/ - 难度:中等 - 解答:[no0017](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0017) 👉 **相似题目**:022. 括号生成 - 题目:https://leetcode-cn.com/problems/generate-parentheses/ - 难度:中等 - 解答:[no0022](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0022) 👉 **相似题目**:301. 删除无效的括号 - 题目:https://leetcode-cn.com/problems/remove-invalid-parentheses/ - 难度:困难 - 解答:[no0301](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0301) ### 093. 复原IP地址 - 题目:https://leetcode-cn.com/problems/restore-ip-addresses/ - 难度:中等 - 解答:[no0093](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0093) ### 079. 单词搜索 - 题目:https://leetcode-cn.com/problems/word-search/ - 难度:中等 - 解答:[no0079](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0079) 👉 **相似题目**:212. 单词搜索 II - 题目:https://leetcode-cn.com/problems/word-search-ii/ - 难度:困难 - 解答:[no0212](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0212) ### 046. 全排列 - 题目:https://leetcode-cn.com/problems/permutations/ - 难度:中等 - 解答:[no0046](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0046) 👉 **相似题目**:047. 全排列 II - 题目:https://leetcode-cn.com/problems/permutations-ii/ - 难度:中等 - 解答:[no0047](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0047) 👉 **相似题目**:996. 正方形数组的数目 - 题目:https://leetcode-cn.com/problems/number-of-squareful-arrays/ - 难度:困难 - 解答:[no0996](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no00996) 👉 **相似题目**:077. 组合 - 题目:https://leetcode-cn.com/problems/combinations/ - 难度:中等 - 解答:[no0077](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0077) 👉 **相似题目**:784. 字母大小写全排列 - 题目:https://leetcode-cn.com/problems/letter-case-permutation/ - 难度:简单 - 解答:[no0784](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0784) 👉 **相似题目**:039. 组合总和 - 题目:https://leetcode-cn.com/problems/combination-sum/ - 难度:中等 - 解答:[no0039](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0039) 👉 **相似题目**:040. 组合总和 II - 题目:https://leetcode-cn.com/problems/combination-sum-ii/ - 难度:中等 - 解答:[no0040](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0040) 👉 **相似题目**:216. 组合总和 III - 题目:https://leetcode-cn.com/problems/combination-sum-iii/ - 难度:中等 - 解答:[no0216](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0216) 👉 **相似题目**:282. 给表达式添加运算符 - 题目:https://leetcode-cn.com/problems/expression-add-operators/ - 难度:困难 - 解答:[no0282](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0282) ### 078. 子集 - 题目:https://leetcode-cn.com/problems/subsets/ - 难度:中等 - 解答:[no0078](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0078) 👉 **相似题目**:090. 子集 II - 题目:https://leetcode-cn.com/problems/subsets-ii/ - 难度:中等 - 解答:[no0090](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0090) ### 131. 分割回文串 - 题目:https://leetcode-cn.com/problems/palindrome-partitioning/ - 难度:中等 - 解答:[no0131](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0131) ### 842. 将数组拆分成斐波那契序列 - 题目:https://leetcode-cn.com/problems/split-array-into-fibonacci-sequence/ - 难度:中等 - 解答:[no0842](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0842) ### 037. 解数独 - 题目:https://leetcode-cn.com/problems/sudoku-solver/ - 难度:困难 - 解答:[no0037](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0037) 👉 **相似题目**:051. N皇后 - 题目:https://leetcode-cn.com/problems/n-queens/ - 难度:中等 - 解答:[no0051](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0051) 👉 **相似题目**:052. N皇后 - 题目:https://leetcode-cn.com/problems/n-queens-ii/ - 难度:中等 - 解答:[no0052](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0052) ## 分治算法 ### 241. 为运算表达式设计优先级 - 题目:https://leetcode-cn.com/problems/different-ways-to-add-parentheses/ - 难度:中等 - 解答:[no0241](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0241) ### 096. 不同的二叉搜索树 - 题目:https://leetcode-cn.com/problems/unique-binary-search-trees/ - 难度:中等 - 解答:[no0096](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0096) 👉 **相似题目**:095. 不同的二叉搜索树 II - 题目:https://leetcode-cn.com/problems/unique-binary-search-trees-ii/ - 难度:中等 - 解答:[no0095](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0095) > 关于下面的众数的题目,只有 169 是通过分治算法解决,并且还不是最优解。最优是 [“Boyer-Moore 投票算法”](https://blog.csdn.net/kimixuchen/article/details/52787307) 。 ### 169. 求众数 - 题目:https://leetcode-cn.com/problems/majority-element/ - 难度:简单 - 解答:[no0169](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0169) 👉 **相似题目**:229. 求众数 II - 题目:https://leetcode-cn.com/problems/majority-element-ii/ - 难度:中等 - 解答:[no0229](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0229) ## 贪心算法 ### 455. 分发饼干 - 题目:https://leetcode-cn.com/problems/assign-cookies/ - 难度:简单 - 解答:[no0455](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0455) ### 435. 无重叠区间 - 题目:https://leetcode-cn.com/problems/non-overlapping-intervals/ - 难度:中等 - 解答:[no0435](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0435) 👉 **相似题目**:452. 用最少数量的箭引爆气球 - 题目:https://leetcode-cn.com/problems/minimum-number-of-arrows-to-burst-balloons/ - 难度:中等 - 解答:[no0452](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0452) ### 406. 根据身高重建队列 - 题目:https://leetcode-cn.com/problems/queue-reconstruction-by-height/ - 难度:中等 - 解答:[no0406](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0406) ### 121. 买卖股票的最佳时机 - 题目:https://leetcode-cn.com/problems/best-time-to-buy-and-sell-stock/ - 难度:简单 - 解答:[no0121](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0121) 👉 **相似题目**:122. 买卖股票的最佳时机 II - 题目:https://leetcode-cn.com/problems/best-time-to-buy-and-sell-stock-ii/ - 难度:简单 - 解答:[no0122](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0122) ### 392. 判断子序列 - 题目:https://leetcode-cn.com/problems/is-subsequence/ - 难度:简单 - 解答:[no0392](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0392) ### 055. 跳跃游戏 - 题目:https://leetcode-cn.com/problems/is-subsequence/ - 难度:简单 - 解答:[no0053](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0053) ### 763. 划分字母区间 - 题目:https://leetcode-cn.com/problems/partition-labels/ - 难度:中等 - 解答:[no0763](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0763) ### 055. 跳跃游戏 - 题目:https://leetcode-cn.com/problems/jump-game/ - 难度:中等 - 解答:[no0055](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0055) 👉 **相似题目**:045. 跳跃游戏 II - 题目:https://leetcode-cn.com/problems/jump-game-ii/ - 难度:困难 - 解答:[no0045](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0045) ## 动态规划 DOING TODO 需要整理下 动态规划题型 - 0-1 背包 - 斐波那契数列 ### 509. 斐波那契数 - 题目:https://leetcode-cn.com/problems/fibonacci-number/ - 难度:简单 - 解答:[no0509](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0509) 👉 **相似题目**:070. 爬楼梯 - 题目:https://leetcode-cn.com/problems/climbing-stairs/ - 难度:简单 - 解答:[no0070](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0070) 👉 **相似题目**:746. 使用最小花费爬楼梯 - 题目:https://leetcode-cn.com/problems/min-cost-climbing-stairs/ - 难度:简单 - 解答:[no0746](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0746) ### 198. 打家劫舍 - 题目:https://leetcode-cn.com/problems/house-robber/ - 难度:简单 - 解答:[no0198](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0198) 👉 **相似题目**:213. 打家劫舍 II - 题目:https://leetcode-cn.com/problems/house-robber-II/ - 难度:中等 - 解答:[no0213](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0213) ### 064. 最小路径和 - 题目:https://leetcode-cn.com/problems/minimum-path-sum/ - 难度:中等 - 解答:[no0064](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0064) 👉 **相似题目**:062. 不同路径 - 题目:https://leetcode-cn.com/problems/unique-paths/ - 难度:中等 - 解答:[no0062](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0062) 👉 **相似题目**:063. 不同路径 II - 题目:https://leetcode-cn.com/problems/unique-paths-ii/ - 难度:中等 - 解答:[no0063](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0063) ### 303. 区域和检索 - 数组不可变 - 题目:https://leetcode-cn.com/problems/range-sum-query-immutable/ - 难度:简单 - 解答:[no0303](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0303) ### 413. 等差数列划分 - 题目:https://leetcode-cn.com/problems/arithmetic-slices/ - 难度:中等 - 解答:[no0413](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0413) ### 343. 整数拆分 - 题目:https://leetcode-cn.com/problems/integer-break/ - 难度:中等 - 解答:[no0343](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0343) ### 091. 解码方法 - 题目:https://leetcode-cn.com/problems/decode-ways/ - 难度:中等 - 解答:[no0091](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0091) ### 416. 分割等和子集 - 题目:https://leetcode-cn.com/problems/partition-equal-subset-sum/ - 难度:中等 - 解答:[no0416](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0416) ### 494. 目标和 - 题目:https://leetcode-cn.com/problems/target-sum/ - 难度:中等 - 解答:[no0494](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0494) ### 474. 一和零 - 题目:https://leetcode-cn.com/problems/ones-and-zeroes/ - 难度:中等 - 解答:[no0474](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0474) ### 322. 零钱兑换 - 题目:https://leetcode-cn.com/problems/coin-change/ - 难度:中等 - 解答:[no0322](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0322) 👉 **相似题目**:518. 零钱兑换 II - 题目:https://leetcode-cn.com/problems/coin-change-2/ - 难度:中等 - 解答:[no0518](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0518) 👉 **相似题目**:377. 组合总和 Ⅳ - 题目:https://leetcode-cn.com/problems/combination-sum-iv/ - 难度:中等 - 解答:[no0377](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0377) ### 139. 单词拆分 - 题目:https://leetcode-cn.com/problems/word-break/ - 难度:中等 - 解答:[no0139](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0139) ### 309. 最佳买卖股票时机含冷冻期 - 题目:https://leetcode-cn.com/problems/best-time-to-buy-and-sell-stock-with-cooldown/ - 难度:中等 - 解答:[no0309](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0309) 👉 **相似题目**:714. 买卖股票的最佳时机含手续费 - 题目:https://leetcode-cn.com/problems/best-time-to-buy-and-sell-stock-with-transaction-fee/ - 难度:中等 - 解答:[no0714](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0714) 👉 **相似题目**:123. 买卖股票的最佳时机 III - 题目:https://leetcode-cn.com/problems/best-time-to-buy-and-sell-stock-iii/ - 难度:困难 - 解答:[no0123](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0123) 👉 **相似题目**:188. 买卖股票的最佳时机 IV - 题目:https://leetcode-cn.com/problems/best-time-to-buy-and-sell-stock-iv/ - 难度:困难 - 解答:[no0188](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0188) ### 221. 最大正方形 - 题目:https://leetcode-cn.com/problems/maximal-square/ - 难度:中等 - 解答:[no0221](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0221) 👉 **相似题目**:085. 最大矩形 - 题目:https://leetcode-cn.com/problems/maximal-rectangle/ - 难度:困难 - 解答:[no0085](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0085) 👉 **相似题目**:84. 柱状图中最大的矩形 - 题目:https://leetcode-cn.com/problems/largest-rectangle-in-histogram/ - 难度:困难 - 解答:[no0084](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0084) ### 152. 乘积最大子序列 - 题目:https://leetcode-cn.com/problems/maximum-product-subarray/ - 难度:中等 - 解答:[no0152](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0152) ## 位运算 > 位操作很骚,有些想不到,真的就是想不到。 ### 461. 汉明距离 - 题目:https://leetcode-cn.com/problems/hamming-distance/ - 难度:简单 - 解答:[no0461](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0461) ### 136. 只出现一次的数字 - 题目:https://leetcode-cn.com/problems/single-number/ - 难度:简单 - 解答:[no0136](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0136) 👉 **相似题目**:268. 缺失数字 - 题目:https://leetcode-cn.com/problems/missing-number/ - 难度:简单 - 解答:[no0268](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0268) 👉 **相似题目**:260. 只出现一次的数字 III - 题目:https://leetcode-cn.com/problems/single-number-iii/ - 难度:中等 - 解答:[no0260](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0260) ### 190. 颠倒二进制位 - 题目:https://leetcode-cn.com/problems/reverse-bits/ - 难度:简单 - 解答:[no0190](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0190) ### 231. 2 的幂 - 题目:https://leetcode-cn.com/problems/power-of-two/ - 难度:简单 - 解答:[no0231](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0231) 👉 **相似题目**:342. 4 的幂 - 题目:https://leetcode-cn.com/problems/power-of-four/ - 难度:简单 - 解答:[no0342](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0342) ### 693. 交替位二进制数 - 题目:https://leetcode-cn.com/problems/binary-number-with-alternating-bits/ - 难度:简单 - 解答:[no0693](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0693) ### 476. 数字的补数 - 题目:https://leetcode-cn.com/problems/number-complement/ - 难度:简单 - 解答:[no0476](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no476) ### 371. 两整数之和 - 题目:https://leetcode-cn.com/problems/sum-of-two-integers/ - 难度:简单 - 解答:[no0371](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0317) ### 318. 最大单词长度乘积 - 题目:https://leetcode-cn.com/problems/maximum-product-of-word-lengths/ - 难度: - 解答:[no0318](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0318) ### 191. 位1的个数 - 题目:https://leetcode-cn.com/problems/number-of-1-bits/ - 难度:简单 - 解答:[no0191](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0191) 👉 **相似题目**:338. 比特位计数 - 题目:https://leetcode-cn.com/problems/counting-bits/ - 难度:中等 - 解答:[no0338](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0338) ## 数学 TODO ## TODO \### - 题目:<> - 难度: - 解答:[no0](https://github.com/YunaiV/algorithm1024/tree/master/src/main/java/cn/iocoder/algorithm/leetcode/no0) 👉 **相似题目**: