# leetcode **Repository Path**: xfanonymous/leetcode ## Basic Information - **Project Name**: leetcode - **Description**: leetcode hustle everyday!!! - **Primary Language**: Java - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2023-05-31 - **Last Updated**: 2026-07-05 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README [toc] # LeetCode题目分类 1. [CodeTop](https://codetop.cc/home) 2. [](https://github.com/azl397985856/leetcode) ## CodeTop100 1. [3. 无重复字符的最长子串](https://leetcode.cn/problems/longest-substring-without-repeating-characters/description/)【Map+指针构造无重复元素滑动窗口】 2. [206. 反转链表](https://leetcode.cn/problems/reverse-linked-list/description/)【链表双指针迭代】 3. [146. LRU 缓存](https://leetcode.cn/problems/lru-cache/description/)【设计】【哈希表】【双向链表】 4. [215. 数组中的第K个最大元素](https://leetcode.cn/problems/kth-largest-element-in-an-array/description/)【数组排序】【优先级队列】【快速排序】 5. [25. K 个一组翻转链表](https://leetcode.cn/problems/reverse-nodes-in-k-group/description/)【链表】【HARD】 6. []() 7. []() 8. []() 9. []() 10. []() 11. []() 12. []() 13. []() 14. []() 15. []() ## Algorithm ### 单调栈 ### 二叉树 # LeetCode记录 - https://github.com/azl397985856/leetcode/tree/master/problems # 笔记 ## 求长度 1. 数组长度,属性: nums.length; 2. 字符串长度,方法: string.length(); 3. 容器,容量大小: deque.size(); ## 快捷方式 1. 快速写for循环:params.length.fori 2. 快速写if条件:get().if 3. 快速打印:sout 4. 快速main方法:psvm # 题目分类 字符串、排序 http://oj.rnd.huawei.com/problems/374/submissions http://oj.rnd.huawei.com/problems/1904/details https://leetcode-cn.com/problems/bianry-number-to-string-lcci/ https://leetcode-cn.com/problems/longest-palindromic-substring/ https://leetcode-cn.com/problems/restore-ip-addresses/ https://leetcode-cn.com/problems/basic-calculator-ii/ 回溯算法 算法思想回溯算法实际上一个类似枚举的搜索尝试过程,主要是在搜索尝试过程中寻找问题的解,当发现已不满足求解条件时,就“回溯”返回,尝试别的路径。其本质就是穷举。 一般解题步骤 针对所给问题,定义问题的解空间,它至少包含问题的一个(最优)解。 确定易于搜索的解空间结构,使得能用回溯法方便地搜索整个解空间 。 以深度优先的方式搜索解空间,并且在搜索过程中用剪枝函数避免无效搜索。 77.组合:https://leetcode.cn/problems/combinations/ 39.组合总和:https://leetcode.cn/problems/combination-sum/ 40.组合总和 II:https://leetcode.cn/problems/combination-sum-ii/ 78.子集:https://leetcode.cn/problems/subsets/ 90.子集 II:https://leetcode.cn/problems/subsets-ii/ 51.N 皇后:https://leetcode.cn/problems/n-queens/ 分治算法 将一个规模为 N 的问题分解为 K 个规模较小的子问题,这些子问题相互独立且与原问题性质相同。求出子问题的解,就可得到原问题的解。 将原问题分解为若干个规模较小,相互独立,与原问题形式相同的子问题; 若子问题规模较小而容易被解决则直接解,否则递归地解各个子问题将各个子问题的解合并为原问题的解。 LeetCode108.将有序数组转换成二叉搜索数:https://leetcode.cn/problems/convert-sorted-array-to-binary-search-tree/ 148.排序列表:https://leetcode.cn/problems/sort-list/ 23.合并 k 个升序链表:https://leetcode.cn/problems/merge-k-sorted-lists/ 链表、队列、哈希 http://oj.rnd.huawei.com/problems/395/details http://oj.rnd.huawei.com/problems/282/details https://leetcode-cn.com/problems/fu-za-lian-biao-de-fu-zhi-lcof/ https://leetcode-cn.com/problems/top-k-frequent-words/ https://leetcode-cn.com/problems/find-the-most-competitive-subsequence/ https://leetcode-cn.com/problems/swapping-nodes-in-a-linked-list/ 滑动窗口、双指针 https://oj.rnd.huawei.com/problems/1809/details http://oj.rnd.huawei.com/problems/1729/details https://leetcode-cn.com/problems/interval-list-intersections/ https://leetcode-cn.com/problems/max-consecutive-ones-iii/ https://leetcode-cn.com/problems/can-you-eat-your-favorite-candy-on-your-favorite-day/ https://leetcode-cn.com/problems/container-with-most-water/ 递归 https://leetcode-cn.com/problems/swap-nodes-in-pairs/ https://leetcode-cn.com/problems/binary-tree-preorder-traversal/ https://leetcode-cn.com/problems/lowest-common-ancestor-of-a-binary-tree/ https://leetcode-cn.com/problems/letter-combinations-of-a-phone-number/ https://leetcode-cn.com/problems/longest-substring-with-at-least-k-repeating-characters/ https://leetcode-cn.com/problems/partition-to-k-equal-sum-subsets/ 树、二叉树 https://leetcode-cn.com/problems/maximum-width-of-binary-tree/ https://leetcode-cn.com/problems/reorder-routes-to-make-all-paths-lead-to-the-city-zero/ https://leetcode-cn.com/problems/binary-tree-level-order-traversal/ https://leetcode-cn.com/problems/maximum-difference-between-node-and-ancestor/ https://oj.rnd.huawei.com/problems/326/details https://oj.rnd.huawei.com/problems/216/details BFS、DFS: https://leetcode-cn.com/problems/flatten-binary-tree-to-linked-list/solution/ https://leetcode-cn.com/problems/course-schedule/solution/ https://leetcode-cn.com/problems/perfect-squares/ https://leetcode-cn.com/problems/course-schedule/ https://oj.rnd.huawei.com/problems/387/details https://oj.rnd.huawei.com/problems/1905/details 贪心 贪心的本质是选择每一阶段的局部最优,从而达到全局最优。 一般解题步骤 将问题分解为若干个子问题 找出适合的贪心策略 求解每一个子问题的最优解 将局部最优解堆叠成全局最优解 455.分发饼干:https://leetcode.cn/problems/assign-cookies/ 121.买卖股票的最佳时机:https://leetcode.cn/problems/best-time-to-buy-and-sell-stock/ 122.买卖股票的最佳时机 II:https://leetcode.cn/problems/best-time-to-buy-and-sell-stock-ii/ 55.跳跃游戏:https://leetcode.cn/problems/jump-game/ 45.跳跃游戏 II:https://leetcode.cn/problems/jump-game-ii/ 动态规划 算法思想 动态规划中每一个状态一定是由上一个状态推导出来的,这一点就区分于贪心,贪心没有状态推导,而是从局部直接选最优的。 经典题目:01 背包、完全背包 一般解题步骤 确定 dp 数组(dp table)以及下标的含义 确定递推公式 dp 数组如何初始化 确定遍历顺序 举例推导 dp 数组 509.斐波那契数:https://leetcode.cn/problems/fibonacci-number/ 746.使用最小花费爬楼梯:https://leetcode.cn/problems/min-cost-climbing-stairs/ 416.分割等和子集:https://leetcode.cn/problems/partition-equal-subset-sum/ 518.零钱兑换:https://leetcode.cn/problems/coin-change-ii/ 647.回文子串:https://leetcode.cn/problems/palindromic-substrings/ 516.最长回文子序列:https://leetcode.cn/problems/longest-palindromic-subsequence/ https://oj.rnd.huawei.com/problems/290/details https://leetcode-cn.com/problems/task-scheduler/ https://leetcode-cn.com/problems/house-robber/ https://leetcode-cn.com/problems/boats-to-save-people/ https://leetcode-cn.com/problems/house-robber-iii/ http://oj.rnd.huawei.com/problems/221/details 打家劫舍专题,大家先做1,再做2,如果有兴趣,可以再做3 https://leetcode-cn.com/problems/house-robber/ https://leetcode-cn.com/problems/house-robber-ii/ https://leetcode-cn.com/problems/house-robber-iii/ 图 200.岛屿数量:https://leetcode.cn/problems/number-of-islands/ 207.课程表:https://leetcode.cn/problems/course-schedule/ 210.课程表 II:https://leetcode.cn/problems/course-schedule-ii/ 堆 215.数组中的第 K 个最大元素:https://leetcode.cn/problems/kth-largest-element-in-an-array/ 216.数据流的中位数:https://leetcode.cn/problems/find-median-from-data-stream/ 217.前 K 个高频元素:https://leetcode.cn/problems/top-k-frequent-elements/ # 剑指offer ## 字符串 1. 字符串基本操作 - 剑指 Offer 05. 替换空格 - 剑指 Offer 58 - II. 左旋转字符串 2. 字符串处理 - 剑指 Offer 58 - I. 翻转单词顺序 - 剑指 Offer 50. 第一个只出现一次的字符 ## 链表 - 剑指 Offer 06. 从尾到头打印链表 linkedList.addFirst(int); ××*************待处理 - 剑指 Offer 24. 反转链表 - 剑指 Offer 35. 复杂链表的复制 - 剑指 Offer 18. 删除链表的节点 - 剑指 Offer 22. 链表中倒数第k个节点 - 剑指 Offer 25. 合并两个排序的链表 - 剑指 Offer 52. 两个链表的第一个公共节点 ## 数组 - 剑指 Offer 21. 调整数组顺序使奇数位于偶数前面 - 剑指 Offer 03. 数组中重复的数字 - [剑指 Offer 53 - I. 在排序数组中查找数字 I](https://leetcode.cn/problems/zai-pai-xu-shu-zu-zhong-cha-zhao-shu-zi-lcof/description/) - [剑指 Offer 53 - II. 0~n-1中缺失的数字](https://leetcode.cn/problems/que-shi-de-shu-zi-lcof/description/) - 剑指 Offer 11. 旋转数组的最小数字 ## 二维数组 - 剑指 Offer 04. 二维数组中的查找 - 剑指 Offer 12. 矩阵中的路径 - 剑指 Offer 13. 机器人的运动范围 ## 队列(辅助栈) - 剑指 Offer 09. 用两个栈实现队列 - 剑指 Offer 30. 包含min函数的栈 - 剑指 Offer 31. 栈的压入、弹出序列 # 设计 - 剑指 Offer 09. 用两个栈实现队列 - 剑指 Offer 30. 包含min函数的栈 ## 二叉树 - 二叉树问题,考虑使用BFS双端队列、递归 1. 二叉树遍历 - [剑指 Offer 32 - I. 从上到下打印二叉树](https://leetcode.cn/problems/cong-shang-dao-xia-da-yin-er-cha-shu-lcof/) - [剑指 Offer 32 - II. 从上到下打印二叉树 II](https://leetcode.cn/problems/cong-shang-dao-xia-da-yin-er-cha-shu-ii-lcof/description/) - 剑指 Offer 32 - III. 从上到下打印二叉树 III(https://leetcode.cn/problems/cong-shang-dao-xia-da-yin-er-cha-shu-iii-lcof/description/) 2. 二叉树镜像 - 剑指 Offer 27. 二叉树的镜像 - 剑指 Offer 28. 对称的二叉树 3. 二叉搜索树 - 剑指 Offer 12. 矩阵中的路径 - 剑指 Offer 36. 二叉搜索树与双向链表 - 剑指 Offer 54. 二叉搜索树的第k大节点 - 剑指 Offer 68 - I. 二叉搜索树的最近公共祖先 4. 平衡二叉树 - 剑指 Offer 55 - II. 平衡二叉树 - 剑指 Offer 68 - II. 二叉树的最近公共祖先 # 多线程 [LeetCode多线程题目](https://leetcode.cn/problemset/concurrency/) - 1114. 按序打印 - 1115. 交替打印 FooBar - 1116. 打印零与奇偶数 - 1117. H2O 生成 - 1195. 交替打印字符串 - 1226. 哲学家进餐 # 算法 ## 单调栈 15、三数之和: vector使用 双指针法:寻找两数满足一定条件,分别移动判断 n个数中找出k个数满足,注意与全排列区分 不重复:排序后方便去重 特判:减少时间复杂度 防止溢出:判断两数相加或多数相加时,先转化成long long型,再相加 返回结果考虑直接添加对应类型 遍历:使用 for while 遍历时,需要添加判断范围,保证++ 或 -- 后的数在要求范围内:while ((i+1 < nums.size()) && (nums[i] == nums[i+1])),否则会报超出内存访问错误 注意首元素去重位置,先判断完当前元素所有情况后,再进行判断,否则会遗漏 ## 双指针 - 剑指 Offer 24. 反转链表 - 剑指 Offer 18. 删除链表的节点 - 剑指 Offer 22. 链表中倒数第k个节点 - 剑指 Offer 25. 合并两个排序的链表 - 剑指 Offer 21. 调整数组顺序使奇数位于偶数前面 - 剑指 Offer 11. 旋转数组的最小数字 ## 哈希表 - 剑指 Offer 35. 复杂链表的复制 - 剑指 Offer 52. 两个链表的第一个公共节点 - 剑指 Offer 03. 数组中重复的数字 - 剑指 Offer 50. 第一个只出现一次的字符 ## 前缀和+哈希表 - 剑指 Offer 57. 和为s的两个数字 - ## 二分 1. 查找左右边界 - [剑指 Offer 53 - I. 在排序数组中查找数字 I](https://leetcode.cn/problems/zai-pai-xu-shu-zu-zhong-cha-zhao-shu-zi-lcof/description/) 2. 查找左边界 - [剑指 Offer 53 - II. 0~n-1中缺失的数字](https://leetcode.cn/problems/que-shi-de-shu-zi-lcof/description/) ## 递归 - [剑指 Offer 26. 树的子结构](https://leetcode.cn/problems/shu-de-zi-jie-gou-lcof/description/) - [剑指 Offer 27. 二叉树的镜像](https://leetcode.cn/problems/er-cha-shu-de-jing-xiang-lcof/description/) - [剑指 Offer 28. 对称的二叉树](https://leetcode.cn/problems/dui-cheng-de-er-cha-shu-lcof/description/) - 剑指 Offer 36. 二叉搜索树与双向链表 - 剑指 Offer 68 - II. 二叉树的最近公共祖先 ## 回溯 - 剑指 Offer 12. 矩阵中的路径 - 剑指 Offer 13. 机器人的运动范围 - 剑指 Offer 34. 二叉树中和为某一值的路径 - 剑指 Offer 55 - I. 二叉树的深度 - 46. 全排列 - 39. 组合总和 - 93. 复原 IP 地址 - 40. 组合总和 II ## 广度优先遍历 BFS - [剑指 Offer 32 - I. 从上到下打印二叉树](https://leetcode.cn/problems/cong-shang-dao-xia-da-yin-er-cha-shu-lcof/) - [剑指 Offer 32 - II. 从上到下打印二叉树 II](https://leetcode.cn/problems/cong-shang-dao-xia-da-yin-er-cha-shu-ii-lcof/description/) - 剑指 Offer 32 - III. 从上到下打印二叉树 III(https://leetcode.cn/problems/cong-shang-dao-xia-da-yin-er-cha-shu-iii-lcof/description/) ## 深度优先遍历 DFS ### 滑动窗口 # 难题 1. 剑指 Offer 12. 矩阵中的路径 2. 剑指 Offer 34. 二叉树中和为某一值的路径 3. 剑指 Offer 36. 二叉搜索树与双向链表 4. 剑指 Offer 68 - II. 二叉树的最近公共祖先