# leetcode **Repository Path**: lonuslan/leetcode ## Basic Information - **Project Name**: leetcode - **Description**: leetcode题库 - **Primary Language**: Java - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 5 - **Forks**: 2 - **Created**: 2020-01-16 - **Last Updated**: 2024-10-11 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # LeetCode [![Travis](https://img.shields.io/badge/language-C++-green.svg)]() [![Travis](https://img.shields.io/badge/language-Python-red.svg)]() [![Travis](https://img.shields.io/badge/language-Java-blue.svg)]() [![Travis](https://img.shields.io/badge/language-Go-red.svg)]() [![Travis](https://img.shields.io/badge/language-Php-pink.svg)]() [![Travis](https://img.shields.io/badge/language-JavaScript-yellow.svg)]() [![](https://img.shields.io/badge/WeChat-微信群-brightgreen)](#哪里能找到我) [![](https://img.shields.io/badge/公众号-力扣加加-blueviolet)](#哪里能找到我) [![](https://img.shields.io/badge/Juejin-掘金-blue)](https://juejin.im/user/58af98305c497d0067780b3b) [![](https://img.shields.io/badge/Zhihu-知乎-blue)](https://www.zhihu.com/people/lu-xiao-13-70) [![](https://img.shields.io/badge/bilili-哔哩哔哩-ff69b4)](https://space.bilibili.com/519510412/) 简体中文 | [English](./README.en.md) --- 我们的 slogan 是: **只有熟练掌握基础的数据结构与算法,才能对复杂问题迎刃有余。** ## 🔥🔥🔥 我的《算法通关之路》出版了 🔥🔥🔥 我的新书《算法通关之路》出版了。 ![](https://tva1.sinaimg.cn/large/008i3skNly1gu39d1zb7qj622g0u013a02.jpg) - [实体版购书链接 1](https://union-click.jd.com/jdc?e=618|pc|&p=JF8BAOAJK1olXgEGUV9cAE4VCl8IGloXWgYCV1tcAE8TBl9MRANLAjZbERscSkAJHTdNTwcKBlMdBgABFksWAm0PG1sWWAcKUFpYFxJSXzI4GAhrA0IDUiM-FjFxQQtKWFx2AlkYElJROEonA24JG1MQWgMEUW5tCEwnQgEIGlkdXAQHUW5cOEsQBmkNElwWXgYGUFxtD0seMzRddVwVWFVWB10PXxtDVDo4K2sWbQECXRMcWgYnM284GGtXMwUKAw5VDEpDA2oBGl4SXwELUF5fCkkQVDtdH1JGX1EAZFxcCU8eMw) - [实体版购书链接 2](https://union-click.jd.com/jdc?e=618|pc|&p=JF8BAM0JK1olXDYCV1ZfC0kWB19MRANLAjZbERscSkAJHTdNTwcKBlMdBgABFksUC20LGVoRQl9HCANtQDt-RAZPBQFwJ0ZEA1hDWh9wdTB2a1cZbQcyVF9cCEMSBGoOHmslXQEyAjBdCUoWAm4NG14WbQcyVFlYDk4eBG8LG1gUXzYFVFdtUx55BG8NSA9GXlRVBAoKXXsnM2w4HFscEEdQGW5tCHsUMy1mE14WDQcCUVxfWk9EBmkOSQsWDwVSVwpcWEoXUG5aElslXwcDUFdt) - [电子版购书链接](https://union-click.jd.com/jdc?e=&p=JF8BAL0JK1olXDYAVVhfD04UAl9MRANLAjZbERscSkAJHTdNTwcKBlMdBgABFkkWBW0PHlgUQl9HCANtcS0SdTFvWVt1X3BkVV4Kc0JxYRtPe1cZbQcyVF9cCEMSBGoOHmslXQEyHzBcOEonA2gKE1oVWwEKXV5cAXsQA2Y4QA57WgYHBwoOCxlAUztfTmslbQUyZG5dOEgnQQFaSQ5FWQYFB1cODhgSVDpaS1hFDwQLUlwJAU5DAWcJHWsXXAcGXW4) ## :blue_book: 电子书 **注意:这里的电子书并不是《算法通关之路》的电子版,而是本仓库内容的电子版!** [在线阅读地址](https://leetcode-solution-leetcode-pp.gitbook.io/leetcode-solution/) ![](https://tva1.sinaimg.cn/large/0081Kckwly1gm3r7y4dt8j30zx0u0hdt.jpg) **限时免费下载!后期随时可能收费** 可以去我的公众号《力扣加加》后台回复电子书获取! > epub 还是有动图的 另外有些内容只在公众号发布,因此大家觉得内容不错的话,可以关注一下。如果再给 ➕ 个星标就更棒啦! ## 图片加载不出来如何解决? ## :calendar:《91 天学算法》限时活动 很多教育机构宣传的 7 天,一个月搞定算法面试的,我大概都了解了下,不怎么靠谱。学习算法这东西,还是要靠积累,没有量变是不可能有质变的。还有的人选择看书,这是一个不错的选择。但是很多人选了过时的或者质量差的书,又或者不会去写书中给的练习题,导致效果很差。 基于这几个原因,我组织了一个 91 天刷题活动,通过一个相对比较长的时间(91 天)给出最新的学习路径,并强制大家打卡这种高强度练习来让大家**在 91 天后遇见更好的自己**。详细活动介绍可以点下方链接查看。另外往期的讲义也在下面了,大家可以看看合不合你的口味。 最后送给大家一句话: **坚持下去,会有突然间成长的一天**。 [点此参与](https://github.com/azl397985856/leetcode/discussions/532) ![](https://tva1.sinaimg.cn/large/008i3skNly1gq0mm4lscqj313h0r0diy.jpg) - 🔥🔥🔥🔥 [活动首页](https://leetcode-solution.cn/91) 🔥🔥🔥🔥 - [91 第三期讲义 - 二分专题(上)](./thinkings/binary-search-1.md) - [91 第三期讲义 - 二分专题(下)](./thinkings/binary-search-2.md) ## :octocat: 仓库介绍 leetcode 题解,记录自己的 leetcode 解题之路。 本仓库目前分为**五个**部分: - 第一个部分是 leetcode 经典题目的解析,包括思路,关键点和具体的代码实现。 - 第二部分是对于数据结构与算法的总结 - 第三部分是 anki 卡片, 将 leetcode 题目按照一定的方式记录在 anki 中,方便大家记忆。 - 第四部分是每日一题,每日一题是在交流群(包括微信和 qq)里进行的一种活动,大家一起 解一道题,这样讨论问题更加集中,会得到更多的反馈。而且 这些题目可以被记录下来,日后会进行筛选添加到仓库的题解模块。 - 第五部分是计划, 这里会记录将来要加入到以上三个部分内容 ## :meat_on_bone: 仓库食用指南 - 这里有一张互联网公司面试中经常考察的问题类型总结的思维导图,我们可以结合图片中的信息分析一下。 ![leetcode-zhihu](https://tva1.sinaimg.cn/large/007S8ZIlly1ghluennxvrj30k00jx0te.jpg) (图片来自 leetcode) 其中算法,主要是以下几种: - 基础技巧:分治、二分、贪心 - 排序算法:快速排序、归并排序、计数排序 - 搜索算法:回溯、递归、深度优先遍历,广度优先遍历,二叉搜索树等 - 图论:最短路径、最小生成树 - 动态规划:背包问题、最长子序列 数据结构,主要有如下几种: - 数组与链表:单 / 双向链表 - 栈与队列 - 哈希表 - 堆:最大堆 / 最小堆 - 树与图:最近公共祖先、并查集 - 字符串:前缀树(字典树) / 后缀树 我在网上找到一份 [《Interview Cheat Sheet》](./assets/cheatsheet.pdf),这个 PDF 列举了面试的**模板步骤**。,详细指示了如何一步步完成面试。 这个 pdf 开头就提到了好的代码三个标准: 1. 可读性 2. 时间复杂度 3. 空间复杂度 这写的太好了。 紧接着,列举了 15 算法面试的步骤。比如步骤一:**当面试官提问完后,你需要先下来关键点(之后再下面写注释和代码)** 看完我的感受就是,**面试只要按照这个来做,成功率蹭蹭提升** ## 数据结构与算法的总结 - [数据结构总览](./thinkings/basic-data-structure.md) - [链表专题](./thinkings/linked-list.md) - [树专题](./thinkings/tree.md) - [堆专题(上)](./thinkings/heap.md) - [堆专题(下)](./thinkings/heap-2.md) - [二分专题(上)](./thinkings/binary-search-1.md) - [二分专题(下)](./thinkings/binary-search-2.md) - [动态规划(重置版)](./thinkings/dynamic-programming.md) - [大话搜索](./thinkings/search.md) - [二叉树的遍历](./thinkings/binary-tree-traversal.md) - [回溯](./thinkings/backtrack.md) - [哈夫曼编码和游程编码](./thinkings/run-length-encode-and-huffman-encode.md) - [布隆过滤器](./thinkings/bloom-filter.md)🖊 - [前缀树](./thinkings/trie.md)🖊 - [《日程安排》专题](https://lucifer.ren/blog/2020/02/03/leetcode-%E6%88%91%E7%9A%84%E6%97%A5%E7%A8%8B%E5%AE%89%E6%8E%92%E8%A1%A8%E7%B3%BB%E5%88%97/) - [《构造二叉树》专题](https://lucifer.ren/blog/2020/02/08/%E6%9E%84%E9%80%A0%E4%BA%8C%E5%8F%89%E6%A0%91%E4%B8%93%E9%A2%98/) - [滑动窗口(思路 + 模板)](./thinkings/slide-window.md) - [位运算](./thinkings/bit.md) - [小岛问题](./thinkings/island.md)🖊 - [最大公约数](./thinkings/GCD.md) - [并查集](./thinkings/union-find.md) - [平衡二叉树专题](./thinkings/balanced-tree.md) - [蓄水池抽样](./thinkings/reservoid-sampling.md) - [单调栈](./thinkings/monotone-stack.md) ## :exclamation: 怎么刷 LeetCode? - [我是如何刷 LeetCode 的](https://www.zhihu.com/question/280279208/answer/824585814) - [算法小白如何高效、快速刷 leetcode?](https://www.zhihu.com/question/321738058/answer/1279464192) - [刷题效率低?或许你就差这么一个插件](https://lucifer.ren/blog/2020/06/06/algo-chrome-extension/) - [力扣刷题插件](https://lucifer.ren/blog/2020/08/16/leetcode-cheat/) ## :computer: 插件 或许是一个可以改变你刷题效率的浏览器扩展插件。 插件地址:。 > 不能访问谷歌商店的朋友可以去我的公众号回复插件获取离线版。强烈推荐大家使用谷歌商店安装, 这样如果有更新可以自动安装,毕竟咱们的插件更新还是蛮快的。 另外大家也可以使用 zerotrac 开发的用于计算力扣中题目分数的网站。这里的分数指的是竞赛分,大家可以根据自己的竞赛分选择稍微比自己竞赛分高一点的题目进行练习,注意这个只是根据通过人数等计算的一个预估分数。地址:https://zerotrac.github.io/leetcode_problem_rating/ ## 精选题解 - [字典序列删除](./selected/a-deleted.md) - [一次搞定前缀和](./selected/atMostK.md) - [字节跳动的算法面试题是什么难度?](./selected/byte-dance-algo-ex.md) - [字节跳动的算法面试题是什么难度?(第二弹)](./selected/byte-dance-algo-ex-2017.md) - [《我是你的妈妈呀》 - 第一期](./selected/mother-01.md) - [一文带你看懂二叉树的序列化](./selected/serialize.md) - [穿上衣服我就不认识你了?来聊聊最长上升子序列](./selected/LIS.md) - [你的衣服我扒了 - 《最长公共子序列》](./selected/LCS.md) - [一文看懂《最大子序列和问题》](./selected/LSS.md) ## leetcode 经典题目的解析(200 多道) > 这里仅列举具有**代表性题目**,并不是全部题目 目前更新了 200 多道题解,加上专题涉及的题目,差不多有 **300 道**。 ### 简单难度题目合集 这里的题目难度比较小, 大多是模拟题,或者是很容易看出解法的题目,另外简单题目一般使用暴力法都是可以解决的。 这个时候只有看一下数据范围,思考下你的算法复杂度就行了。 当然也不排除很多 hard 题目也可以暴力模拟,大家平时多注意数据范围即可。 以下是我列举的经典题目(带 91 字样的表示出自 **91 天学算法**活动): - [面试题 17.12. BiNode](./problems/binode-lcci.md) 👍 - [0001. 两数之和](./problems/1.two-sum.md) - [0020. 有效的括号](./problems/20.valid-parentheses.md) - [0021. 合并两个有序链表](./problems/21.merge-two-sorted-lists.md) - [0026. 删除排序数组中的重复项](./problems/26.remove-duplicates-from-sorted-array.md) - [0053. 最大子序和](./problems/53.maximum-sum-subarray-cn.md) - [0066. 加一](./problems/66.plus-one.md) 91 - [0088. 合并两个有序数组](./problems/88.merge-sorted-array.md) - [0101. 对称二叉树](./problems/101.symmetric-tree.md) - [0104. 二叉树的最大深度](./problems/104.maximum-depth-of-binary-tree.md) - [0108. 将有序数组转换为二叉搜索树](./problems/108.convert-sorted-array-to-binary-search-tree.md) - [0121. 买卖股票的最佳时机](./problems/121.best-time-to-buy-and-sell-stock.md) - [0122. 买卖股票的最佳时机 II](./problems/122.best-time-to-buy-and-sell-stock-ii.md) - [0125. 验证回文串](./problems/125.valid-palindrome.md) - [0136. 只出现一次的数字](./problems/136.single-number.md) - [0155. 最小栈](./problems/155.min-stack.md) 👍 - [0160. 相交链表](./problems/160.Intersection-of-Two-Linked-Lists.md) 91 - [0167. 两数之和 II 输入有序数组](./problems/167.two-sum-ii-input-array-is-sorted.md) - [0169. 多数元素](./problems/169.majority-element.md) - [0172. 阶乘后的零](./problems/172.factorial-trailing-zeroes.md) - [0190. 颠倒二进制位](./problems/190.reverse-bits.md) - [0191. 位 1 的个数](./problems/191.number-of-1-bits.md) - [0198. 打家劫舍](./problems/198.house-robber.md) - [0203. 移除链表元素](./problems/203.remove-linked-list-elements.md) - [0206. 反转链表](./problems/206.reverse-linked-list.md) - [0219. 存在重复元素 II](./problems/219.contains-duplicate-ii.md) - [0226. 翻转二叉树](./problems/226.invert-binary-tree.md) - [0232. 用栈实现队列](./problems/232.implement-queue-using-stacks.md) 👍 91 - [0263. 丑数](./problems/263.ugly-number.md) - [0283. 移动零](./problems/283.move-zeroes.md) - [0342. 4 的幂](./problems/342.power-of-four.md) 👍 - [0349. 两个数组的交集](./problems/349.intersection-of-two-arrays.md) - [0371. 两整数之和](./problems/371.sum-of-two-integers.md) - [401. 二进制手表](./problems/401.binary-watch.md) - [0437. 路径总和 III](./problems/437.path-sum-iii.md) - [0455. 分发饼干](./problems/455.AssignCookies.md) - [0504. 七进制数](./problems/504.base-7.md) - [0575. 分糖果](./problems/575.distribute-candies.md) - [0606. 根据二叉树创建字符串](./problems/606.construct-string-from-binary-tree.md) - [0661. 图片平滑器](./problems/661.image-smoother.md) - [0665. 非递减数列](./problems/665.non-decreasing-array.md) - [821. 字符的最短距离](./problems/821.shortest-distance-to-a-character.md) 91 - [0874. 模拟行走机器人](./problems/874.walking-robot-simulation.md) - [1128. 等价多米诺骨牌对的数量](./problems/1128.number-of-equivalent-domino-pairs.md) - [1260. 二维网格迁移](./problems/1260.shift-2d-grid.md) - [1332. 删除回文子序列](./problems/1332.remove-palindromic-subsequences.md) ### 中等难度题目合集 中等题目是力扣比例最大的部分,因此这部分我的题解也是最多的。 大家不要太过追求难题,先把中等难度题目做熟了再说。 这部分的题目要不需要我们挖掘题目的内含信息, 将其抽象成简单题目。 要么是一些写起来比较麻烦的题目, 一些人编码能力不行就挂了。因此大家一定要自己做, 即使看了题解 ”会了“,也要自己码一遍。自己不亲自写一遍,里面的细节永远不知道。 以下是我列举的经典题目(带 91 字样的表示出自 **91 天学算法**活动): - [面试题 17.09. 第 k 个数](./problems/get-kth-magic-number-lcci.md) - [面试题 17.23. 最大黑方阵](./problems/max-black-square-lcci.md) - [面试题 16.16. 部分排序](./problems/sub-sort-lcci.md) - [Increasing Digits](./problems/Increasing-Digits.md) 👍 - [Longest Contiguously Strictly Increasing Sublist After Deletion](./problems/Longest-Contiguously-Strictly-Increasing-Sublist-After-Deletion.md) 👍 - [Consecutive Wins](./problems/consecutive-wins.md) - [Sort-String-by-Flipping](./problems/Sort-String-by-Flipping.md) - [Number of Substrings with Single Character Difference](./problems/Number-of-Substrings-with-Single-Character-Difference.md) - [Bus Fare](./problems/Bus-Fare.md) 👍 - [Minimum Dropping Path Sum](./problems/Minimum-Dropping-Path-Sum.md) - [Longest-Matrix-Path-Length](./problems/Longest-Matrix-Path-Length.md) - [Every Sublist Min Sum](./problems/Every-Sublist-Min-Sum.md) - [Maximize the Number of Equivalent Pairs After Swaps](./problems/Maximize-the-Number-of-Equivalent-Pairs-After-Swaps.md) - [0002. 两数相加](./problems/2.add-two-numbers.md) - [0003. 无重复字符的最长子串](./problems/3.longest-substring-without-repeating-characters.md) - [0005. 最长回文子串](./problems/5.longest-palindromic-substring.md) - [0011. 盛最多水的容器](./problems/11.container-with-most-water.md) - [0015. 三数之和](./problems/15.3sum.md) - [0017. 电话号码的字母组合](./problems/17.Letter-Combinations-of-a-Phone-Number.md) - [0019. 删除链表的倒数第 N 个节点](./problems/19.removeNthNodeFromEndofList.md) - [0022. 括号生成](./problems/22.generate-parentheses.md) - [0024. 两两交换链表中的节点](./problems/24.swapNodesInPairs.md) - [0029. 两数相除](./problems/29.divide-two-integers.md) - [0031. 下一个排列](./problems/31.next-permutation.md) - [0033. 搜索旋转排序数组](./problems/33.search-in-rotated-sorted-array.md) - [0039. 组合总和](./problems/39.combination-sum.md) - [0040. 组合总和 II](./problems/40.combination-sum-ii.md) - [0046. 全排列](./problems/46.permutations.md) - [0047. 全排列 II](./problems/47.permutations-ii.md) - [0048. 旋转图像](./problems/48.rotate-image.md) - [0049. 字母异位词分组](./problems/49.group-anagrams.md) - [0050. Pow(x, n)](./problems/50.pow-x-n.md) 👍 - [0055. 跳跃游戏](./problems/55.jump-game.md) - [0056. 合并区间](./problems/56.merge-intervals.md) - [0060. 第 k 个排列](./problems/60.permutation-sequence.md) 👍 - [0061. 旋转链表](./problems/61.Rotate-List.md) 91 - [0062. 不同路径](./problems/62.unique-paths.md) - [0073. 矩阵置零](./problems/73.set-matrix-zeroes.md) - [0075. 颜色分类](./problems/75.sort-colors.md) 👍 - [0078. 子集](./problems/78.subsets.md) - [0079. 单词搜索](./problems/79.word-search.md) - [0080. 删除排序数组中的重复项 II](./problems/80.remove-duplicates-from-sorted-array-ii.md) - [0086. 分隔链表](./problems/86.partition-list.md) - [0090. 子集 II](./problems/90.subsets-ii.md) - [0091. 解码方法](./problems/91.decode-ways.md) - [0092. 反转链表 II](./problems/92.reverse-linked-list-ii.md) - [0094. 二叉树的中序遍历](./problems/94.binary-tree-inorder-traversal.md) 👍 - [0095. 不同的二叉搜索树 II](./problems/95.unique-binary-search-trees-ii.md) - [0096. 不同的二叉搜索树](./problems/96.unique-binary-search-trees.md) - [0098. 验证二叉搜索树](./problems/98.validate-binary-search-tree.md) - [0102. 二叉树的层序遍历](./problems/102.binary-tree-level-order-traversal.md) - [0103. 二叉树的锯齿形层次遍历](./problems/103.binary-tree-zigzag-level-order-traversal.md) - [0113. 路径总和 II](./problems/113.path-sum-ii.md) - [0129. 求根到叶子节点数字之和](./problems/129.sum-root-to-leaf-numbers.md) 👍 - [0130. 被围绕的区域](./problems/130.surrounded-regions.md) - [0131. 分割回文串](./problems/131.palindrome-partitioning.md) - [0139. 单词拆分](./problems/139.word-break.md) - [0144. 二叉树的前序遍历](./problems/144.binary-tree-preorder-traversal.md) - [0147. 对链表进行插入排序](./problems/147.insertion-sort-list.md) - [0150. 逆波兰表达式求值](./problems/150.evaluate-reverse-polish-notation.md) - [0152. 乘积最大子数组](./problems/152.maximum-product-subarray.md) - [0153. 寻找旋转排序数组中的最小值](./problems/153.find-minimum-in-rotated-sorted-array.md) - [0199. 二叉树的右视图](./problems/199.binary-tree-right-side-view.md) 👍 - [0200. 岛屿数量](./problems/200.number-of-islands.md) 👍 - [0201. 数字范围按位与](./problems/201.bitwise-and-of-numbers-range.md) - [0208. 实现 Trie (前缀树)](./problems/208.implement-trie-prefix-tree.md) - [0209. 长度最小的子数组](./problems/209.minimum-size-subarray-sum.md) - [0211. 添加与搜索单词 - 数据结构设计](./problems/211.add-and-search-word-data-structure-design.md) - [0215. 数组中的第 K 个最大元素](./problems/215.kth-largest-element-in-an-array.md) - [0220. 存在重复元素 III](./problems/220.contains-duplicate-iii.md) - [0221. 最大正方形](./problems/221.maximal-square.md) - [0227. 基本计算器 II](./problems/227.basic-calculator-ii.md) - [0229. 求众数 II](./problems/229.majority-element-ii.md) - [0230. 二叉搜索树中第 K 小的元素](./problems/230.kth-smallest-element-in-a-bst.md) - [0236. 二叉树的最近公共祖先](./problems/236.lowest-common-ancestor-of-a-binary-tree.md) - [0238. 除自身以外数组的乘积](./problems/238.product-of-array-except-self.md) - [0240. 搜索二维矩阵 II](./problems/240.search-a-2-d-matrix-ii.md) - [0279. 完全平方数](./problems/279.perfect-squares.md) - [0309. 最佳买卖股票时机含冷冻期](./problems/309.best-time-to-buy-and-sell-stock-with-cooldown.md) - [0322. 零钱兑换](./problems/322.coin-change.md) 👍 - [0324. 摆动排序 II](./problems/324.wiggle-sort-ii.md) - [0328. 奇偶链表](./problems/328.odd-even-linked-list.md) - [0331. 验证二叉树的前序序列化](./problems/331.verify-preorder-serialization-of-a-binary-tree.md) - [0334. 递增的三元子序列](./problems/334.increasing-triplet-subsequence.md) - [0337. 打家劫舍 III](./problems/337.house-robber-iii.md) - [0343. 整数拆分](./problems/343.integer-break.md) - [0365. 水壶问题](./problems/365.water-and-jug-problem.md) - [0378. 有序矩阵中第 K 小的元素](./problems/378.kth-smallest-element-in-a-sorted-matrix.md) - [0380. 常数时间插入、删除和获取随机元素](./problems/380.insert-delete-getrandom-o1.md) - [0385. 迷你语法分析器](./problems/385.mini-parser.md) - [0394. 字符串解码](./problems/394.decode-string.md) 91 - [0416. 分割等和子集](./problems/416.partition-equal-subset-sum.md) - [0424. 替换后的最长重复字符](./problems/424.longest-repeating-character-replacement.md) - [0438. 找到字符串中所有字母异位词](./problems/438.find-all-anagrams-in-a-string.md) - [0445. 两数相加 II](./problems/445.add-two-numbers-ii.md) - [0454. 四数相加 II](./problems/454.4-sum-ii.md) - [0456. 132 模式](./problems/456.132-pattern.md) - [0457.457. 环形数组是否存在循环](./problems/457.circular-array-loop.md) - [0464. 我能赢么](./problems/464.can-i-win.md) - [0470. 用 Rand7() 实现 Rand10](./problems/470.implement-rand10-using-rand7.md) - [0473. 火柴拼正方形](./problems/473.matchsticks-to-square.md) 👍 - [0494. 目标和](./problems/494.target-sum.md) - [0516. 最长回文子序列](./problems/516.longest-palindromic-subsequence.md) - [0513. 找树左下角的值](./problems/513.find-bottom-left-tree-value.md) 91 - [0518. 零钱兑换 II](./problems/518.coin-change-2.md) - [0525. 连续数组](./problems/525.contiguous-array.md) - [0547. 省份数量](./problems/547.number-of-provinces.md) - [0560. 和为 K 的子数组](./problems/560.subarray-sum-equals-k.md) - [0609. 在系统中查找重复文件](./problems/609.find-duplicate-file-in-system.md) - [0611. 有效三角形的个数](./problems/611.valid-triangle-number.md) 👍 - [0673. 最长递增子序列的个数](./problems/673.number-of-longest-increasing-subsequence.md) - [0686. 重复叠加字符串匹配](./problems/686.repeated-string-match.md) - [0710. 黑名单中的随机数](./problems/710.random-pick-with-blacklist.md) - [0714. 买卖股票的最佳时机含手续费](./problems/714.best-time-to-buy-and-sell-stock-with-transaction-fee.md) - [0718. 最长重复子数组](./problems/718.maximum-length-of-repeated-subarray.md) - [0735. 行星碰撞](./problems/735.asteroid-collision.md) 👍 - [0754. 到达终点数字](./problems/754.reach-a-number.md) - [0785. 判断二分图](./problems/785.is-graph-bipartite.md) - [0790. 多米诺和托米诺平铺](./problems/790.domino-and-tromino-tiling.md) - [0799. 香槟塔](./problems/799.champagne-tower.md) - [0801. 使序列递增的最小交换次数](./problems/801.minimum-swaps-to-make-sequences-increasing.md) - [0816. 模糊坐标](./problems/816.ambiguous-coordinates.md) - [0820. 单词的压缩编码](./problems/820.short-encoding-of-words.md) - [0838. 推多米诺](./problems/838.push-dominoes.md) - [0873. 最长的斐波那契子序列的长度](./problems/873.length-of-longest-fibonacci-subsequence.md) - [0875. 爱吃香蕉的珂珂](./problems/875.koko-eating-bananas.md) - [0877. 石子游戏](./problems/877.stone-game.md) - [0886. 可能的二分法](./problems/886.possible-bipartition.md) - [0898. 子数组按位或操作](./problems/898.bitwise-ors-of-subarrays.md) - [0900. RLE 迭代器](./problems/900.rle-iterator.md) - [0911. 在线选举](./problems/911.online-election.md) - [0912. 排序数组](./problems/912.sort-an-array.md) - [0932. 漂亮数组](./problems/932.beautiful-array.md) - [0935. 骑士拨号器](./problems/935.knight-dialer.md) - [0947. 移除最多的同行或同列石头](./problems/947.most-stones-removed-with-same-row-or-column.md) - [0959. 由斜杠划分区域](./problems/959.regions-cut-by-slashes.md) - [0978. 最长湍流子数组](./problems/978.longest-turbulent-subarray.md) - [0987. 二叉树的垂序遍历](./problems/987.vertical-order-traversal-of-a-binary-tree.md) 91 - [1004. 最大连续 1 的个数 III](./problems/1004.max-consecutive-ones-iii.md) - [1011. 在 D 天内送达包裹的能力](./problems/1011.capacity-to-ship-packages-within-d-days.md) - [1014. 最佳观光组合](./problems/1014.best-sightseeing-pair.md) - [1015. 可被 K 整除的最小整数](./problems/1015.smallest-integer-divisible-by-k.md) - [1019. 链表中的下一个更大节点](./problems/1019.next-greater-node-in-linked-list.md) - [1020. 飞地的数量](./problems/1020.number-of-enclaves.md) - [1023. 驼峰式匹配](./problems/1023.camelcase-matching.md) - [1031. 两个非重叠子数组的最大和](./problems/1031.maximum-sum-of-two-non-overlapping-subarrays.md) - [1043. 分隔数组以得到最大和](./problems/1043.partition-array-for-maximum-sum.md) - [1104. 二叉树寻路](./problems/1104.path-in-zigzag-labelled-binary-tree.md) - [1129. 颜色交替的最短路径](./problems/1129.shortest-path-with-alternating-colors.md) - [1131. 绝对值表达式的最大值](./problems/1131.maximum-of-absolute-value-expression.md) - [1138. 字母板上的路径](./problems/1138.alphabet-board-path.md) - [1186. 删除一次得到子数组最大和](./problems/1186.maximum-subarray-sum-with-one-deletion.md) - [1218. 最长定差子序列](./problems/1218.longest-arithmetic-subsequence-of-given-difference.md) - [1227. 飞机座位分配概率](./problems/1227.airplane-seat-assignment-probability.md) 👍 - [1261. 在受污染的二叉树中查找元素](./problems/1261.find-elements-in-a-contaminated-binary-tree.md) - [1262. 可被三整除的最大和](./problems/1262.greatest-sum-divisible-by-three.md) - [1297. 子串的最大出现次数](./problems/1297.maximum-number-of-occurrences-of-a-substring.md) - [1310. 子数组异或查询](./problems/1310.xor-queries-of-a-subarray.md) - [1334. 阈值距离内邻居最少的城市](./problems/1334.find-the-city-with-the-smallest-number-of-neighbors-at-a-threshold-distance.md) - [1371. 每个元音包含偶数次的最长子字符串](./problems/1371.find-the-longest-substring-containing-vowels-in-even-counts.md) - [1381. 设计一个支持增量操作的栈](./problems/1381.design-a-stack-with-increment-operation.md) 91 - [1423. 可获得的最大点数](./problems/1423.maximum-points-you-can-obtain-from-cards.md) - [1438. 绝对差不超过限制的最长连续子数组](./problems/1438.longest-continuous-subarray-with-absolute-diff-less-than-or-equal-to-limit.md) - [1558. 得到目标数组的最少函数调用次数](./problems/1558.minimum-numbers-of-function-calls-to-make-target-array.md) - [1574. 删除最短的子数组使剩余数组有序](./problems/1574.shortest-subarray-to-be-removed-to-make-array-sorted.md) - [1589. 所有排列中的最大和](./problems/1589.maximum-sum-obtained-of-any-permutation.md) - [1631. 最小体力消耗路径](./problems/1631.path-with-minimum-effort.md) - [1658. 将 x 减到 0 的最小操作数](./problems/1658.minimum-operations-to-reduce-x-to-zero.md) - [1697. 检查边长度限制的路径是否存在](./problems/1697.checking-existence-of-edge-length-limited-paths.md) - [1737. 满足三条件之一需改变的最少字符数](./problems/1737.change-minimum-characters-to-satisfy-one-of-three-conditions.md) - [1834. 单线程 CPU](./problems/1834.single-threaded-cpu.md) - [1899. 合并若干三元组以形成目标三元组](./problems/1899.merge-triplets-to-form-target-triplet.md) 👍 - [1904. 你完成的完整对局数](./problems/1904.the-number-of-full-rounds-you-have-played.md) - [1906. 查询差绝对值的最小值](./problems/1906.minimum-absolute-difference-queries.md) - [2007. 从双倍数组中还原原数组](./problems/2007.find-original-array-from-doubled-array.md) - [2008. 出租车的最大盈利](./problems/2008.maximum-earnings-from-taxi.md) - [5935. 适合打劫银行的日子](./problems/5935.find-good-days-to-rob-the-bank.md) - [5936. 引爆最多的炸弹](./problems/5936.detonate-the-maximum-bombs.md) - [5965. 相同元素的间隔之和](./problems/5965.intervals-between-identical-elements.md) - [6021. 字符串中最多数目的子字符串](./problems/6201.maximize-number-of-subsequences-in-a-string.md) ### 困难难度题目合集 困难难度题目从类型上说多是: - 图 - 设计题 - 游戏场景题目 - 中等题目的 follow up 从解法上来说,多是: - 图算法 - 动态规划 - 二分法 - DFS & BFS - 状态压缩 - 剪枝 从逻辑上说, 要么就是非常难想到,要么就是非常难写代码。 这里我总结了几个技巧: 1. 看题目的数据范围, 看能否暴力模拟 2. 暴力枚举所有可能的算法往上套,比如图的题目。 3. 总结和记忆解题模板,减少解题压力 以下是我列举的经典题目(带 91 字样的表示出自 **91 天学算法**活动): - [LCP 20. 快速公交](./problems/lcp20.meChtZ.md) - [LCP 21. 追逐游戏](./problems/lcp21.Za25hA.md) 👍 - [Number Stream to Intervals](./problems/Number-Stream-to-Intervals.md) - [Triple Inversion](./problems/Triple-Inversion.md) 91 - [Kth Pair Distance](./problems/Kth-Pair-Distance.md) 91 - [Minimum Light Radius](./problems/Minimum-Light-Radius.md) 91 - [Largest Equivalent Set of Pairs](./problems/Largest-Equivalent-Set-of-Pairs.md) 👍 - [Ticket-Order.md](./problems/Ticket-Order.md) - [Connected-Road-to-Destination](./problems/Connected-Road-to-Destination.md) - [0004. 寻找两个正序数组的中位数](./problems/4.median-of-two-sorted-arrays.md) 👍 - [0023. 合并 K 个升序链表](./problems/23.merge-k-sorted-lists.md) - [0025. K 个一组翻转链表](./problems/25.reverse-nodes-in-k-groups.md) 👍 - [0030. 串联所有单词的子串](./problems/30.substring-with-concatenation-of-all-words.md) - [0032. 最长有效括号](./problems/32.longest-valid-parentheses.md) - [0042. 接雨水](./problems/42.trapping-rain-water.md) - [0052. N 皇后 II](./problems/52.N-Queens-II.md) - [0057. 插入区间](problems/57.insert-interval.md) - [0065. 有效数字](problems/65.valid-number.md) - [0084. 柱状图中最大的矩形](./problems/84.largest-rectangle-in-histogram.md) - [0085. 最大矩形](./problems/85.maximal-rectangle.md) - [0087. 扰乱字符串](./problems/87.scramble-string.md) - [0124. 二叉树中的最大路径和](./problems/124.binary-tree-maximum-path-sum.md) - [0128. 最长连续序列](./problems/128.longest-consecutive-sequence.md) - [0132. 分割回文串 II](./problems/132.palindrome-partitioning-ii.md) 👍 - [0140. 单词拆分 II](problems/140.word-break-ii.md) - [0145. 二叉树的后序遍历](./problems/145.binary-tree-postorder-traversal.md) - [0146. LRU 缓存机制](./problems/146.lru-cache.md) - [0154. 寻找旋转排序数组中的最小值 II](./problems/154.find-minimum-in-rotated-sorted-array-ii.md) - [0212. 单词搜索 II](./problems/212.word-search-ii.md) - [0239. 滑动窗口最大值](./problems/239.sliding-window-maximum.md) 👍 - [0295. 数据流的中位数](./problems/295.find-median-from-data-stream.md) - [0297. 二叉树的序列化与反序列化](./problems/297.serialize-and-deserialize-binary-tree.md) 91 - [0301. 删除无效的括号](./problems/301.remove-invalid-parentheses.md) - [0312. 戳气球](./problems/312.burst-balloons.md) - [330. 按要求补齐数组](./problems/330.patching-array.md) - [0335. 路径交叉](./problems/335.self-crossing.md) - [0460. LFU 缓存](./problems/460.lfu-cache.md) - [0472. 连接词](./problems/472.concatenated-words.md) - [0480. 滑动窗口中位数](./problems/480.sliding-window-median.md) - [0483. 最小好进制](./problems/483.smallest-good-base.md) - [0488. 祖玛游戏](./problems/488.zuma-game.md) - [0493. 翻转对](./problems/493.reverse-pairs.md) - [0664. 奇怪的打印机](./problems/664.strange-printer.md) - [0679. 24 点游戏](./problems/679.24-game.md) - [0715. Range 模块](./problems/715.range-module.md) 👍 - [0726. 原子的数量](./problems/726.number-of-atoms.md) - [0768. 最多能完成排序的块 II](./problems/768.max-chunks-to-make-sorted-ii.md) 91 - [0805. 数组的均值分割](./problems/805.split-array-with-same-average.md) - [0839. 相似字符串组](./problems/839.similar-string-groups.md) - [0887. 鸡蛋掉落](./problems/887.super-egg-drop.md) - [0895. 最大频率栈](./problems/895.maximum-frequency-stack.md) - [0909. 蛇梯棋](./problems/909.snakes-and-ladders.md) - [0975. 奇偶跳](./problems/975.odd-even-jump.md) - [0995. K 连续位的最小翻转次数](./problems/995.minimum-number-of-k-consecutive-bit-flips.md) - [1032. 字符流](./problems/1032.stream-of-characters.md) - [1168. 水资源分配优化](./problems/1168.optimize-water-distribution-in-a-village.md) - [1178. 猜字谜](./problems/1178.number-of-valid-words-for-each-puzzle.md) - [1203. 项目管理](./problems/1203.sort-items-by-groups-respecting-dependencies.md) - [1255. 得分最高的单词集合](./problems/1255.maximum-score-words-formed-by-letters.md) - [1345. 跳跃游戏 IV](./problems/1435.jump-game-iv.md) - [1449. 数位成本和为目标值的最大数字](./problems/1449.form-largest-integer-with-digits-that-add-up-to-target.md) - [1494. 并行课程 II](./problems/1494.parallel-courses-ii.md) - [1521. 找到最接近目标值的函数值](./problems/1521.find-a-value-of-a-mysterious-function-closest-to-target.md) - [1526. 形成目标数组的子数组最少增加次数](./problems/1526.minimum-number-of-increments-on-subarrays-to-form-a-target-array.md) - [1649. 通过指令创建有序数组](./problems/1649.create-sorted-array-through-instructions.md) - [1671. 得到山形数组的最少删除次数](./problems/1671.minimum-number-of-removals-to-make-mountain-array.md) - [1707. 与数组中元素的最大异或值](./problems/5640.maximum-xor-with-an-element-from-array.md) - [1713. 得到子序列的最少操作次数](./problems/1713.minimum-operations-to-make-a-subsequence.md) - [1723. 完成所有工作的最短时间](./problems/1723.find-minimum-time-to-finish-all-jobs.md) - [1787. 使所有区间的异或结果为零](./problems/1787.make-the-xor-of-all-segments-equal-to-zero.md) - [1835. 所有数对按位与结果的异或和](./problems/1835.find-xor-sum-of-all-pairs-bitwise-and.md) - [1871. 跳跃游戏 VII](./problems/1871.jump-game-vii.md) 👍 - [1872. 石子游戏 VIII](./problems/1872.stone-game-viii.md) - [1883. 准时抵达会议现场的最小跳过休息次数](./problems/5775.minimum-skips-to-arrive-at-meeting-on-time.md) - [1970. 你能穿过矩阵的最后一天](./problems/1970.last-day-where-you-can-still-cross.md) - [2009. 使数组连续的最少操作数](./problems/2009.minimum-number-of-operations-to-make-array-continuous.md) - [2025. 分割数组的最多方案数](./problems/2025.maximum-number-of-ways-to-partition-an-array.md) - [2030. 含特定字母的最小子序列](./problems/2030.smallest-k-length-subsequence-with-occurrences-of-a-letter.md) - [2102. 序列顺序查询](./problems/2102.sequentially-ordinal-rank-tracker.md) - [2209. 用地毯覆盖后的最少白色砖块](./problems/2209.minimum-white-tiles-after-covering-with-carpets.md) 👍 - [2281. 巫师的总力量和](./problems/2281.sum-of-total-strength-of-wizards.md) - [2306. 公司命名](./problems/2306.naming-a-company.md) 枚举优化好题 - [5254. 卖木头块](./problems/5254.selling-pieces-of-wood.md) 动态规划经典题 - [5999. 统计数组中好三元组数目](./problems/5999.count-good-triplets-in-an-array.md) 👍 ## :trident:  anki 卡片 Anki 主要分为两个部分:一部分是关键点到题目的映射,另一部分是题目到思路,关键点,代码的映射。 全部卡片都在 [anki-card](./assets/anki/leetcode.apkg) 使用方法: anki - 文件 - 导入 - 下拉格式选择“打包的 anki 集合”,然后选中你下载好的文件,确定即可。 更多关于 anki 使用方法的请查看 [anki 官网](https://apps.ankiweb.net/) ## 关于我 大家也可以加我微信好友进行交流! ![](https://tva1.sinaimg.cn/large/008i3skNly1gx11szd02ej30e80e8dg3.jpg) ## :chart_with_upwards_trend: 大事件 - 2019-07-10 :[纪念项目 Star 突破 1W 的一个短文](./thanksGiving.md), 记录了项目的"兴起"之路,大家有兴趣可以看一下,如果对这个项目感兴趣,请**点击一下 Star**, 项目会**持续更新**,感谢大家的支持。 - 2019-10-08: [纪念 LeetCode 项目 Star 突破 2W](./thanksGiving2.md),并且 Github 搜索“LeetCode”,排名第一。 - 2020-04-12: [项目突破三万 Star](./thanksGiving3.md)。 - 2020-04-14: 官网`力扣加加`上线啦 💐💐💐💐💐,有专题讲解,每日一题,下载区和视频题解,后续会增加更多内容,还不赶紧收藏起来?地址: ![](https://tva1.sinaimg.cn/large/007S8ZIlly1ghluemaoj3j30z90dtmy5.jpg) - 2021-02-23: star 破四万 ## :gift_heart: 贡献 - 如果有想法和创意,请提 [issue](https://github.com/azl397985856/leetcode/issues) 或者进群提 - 如果想贡献增加题解或者翻译, 可以参考 [贡献指南](./CONTRIBUTING.md) > 关于如何提交题解,我写了一份 [指南](./templates/problems/1014.best-sightseeing-pair.md) - 如果需要修改项目中图片,[这里](./assets/drawio/) 存放了项目中绘制图的源代码,大家可以用 [draw.io](https://www.draw.io/) 打开进行编辑。 ## :love_letter: 鸣谢 感谢为这个项目作出贡献的所有 [小伙伴](https://github.com/azl397985856/leetcode/graphs/contributors) ## License [CC BY-NC-ND 4.0](./LICENSE.txt)