一二分法最大的最小正向看起来能够用数值去累加去一个个遍历但是估计慢而且也不好做。那么逆向。或者正向数据范围特别大10^15这样。二:比较难的单调栈下一个最大单调栈给你一个整数数组 nums 数组中共有 n 个整数。132 模式的子序列 由三个整数 nums[i]、nums[j] 和 nums[k] 组成并同时满足i j k 和 nums[i] nums[k] nums[j] https://leetcode.cn/problems/132-pattern/description/三路径总和前缀和代表题目https://leetcode.cn/problems/path-sum-iii/四连续子数组滑动窗口或者是前缀和哈希表代表题目https://leetcode.cn/problems/contiguous-array/solutions/809683/lian-xu-shu-zu-by-leetcode-solution-mvnm/同组用哈希表存也有可能数据变化成负数好前缀和索引https://leetcode.cn/problems/A1NYOS/滑动窗口二分法连续子数组k余数并且无限操作连续数组动态规划https://leetcode.cn/problems/minimum-sum-after-divisible-sum-deletions/solutions/3755268/dong-tai-gui-hua-qian-zhui-he-pythonjava-nia8/五差分数组这个一般是针对目标进行的也是这题https://leetcode.cn/problems/contiguous-array/solutions/809683/lian-xu-shu-zu-by-leetcode-solution-mvnm/其实蕴含了差分数组的思想否则你保存1有n个,0有m个你需要遍历min(n,m)遍复杂度是o(n^2)的。如果是差分那么只有1次就行。我只需要获得abs(m-n)即可。可以理解为答案聚类。还有一题是这个https://leetcode.cn/problems/minimum-moves-to-make-array-complementary/solutions/502422/jie-zhe-ge-wen-ti-xue-xi-yi-xia-chai-fen-shu-zu-on/得到的是差分还有线段树问题可以转换为差分问题https://leetcode.cn/problems/count-positions-on-street-with-required-brightness/description/六排序双指针与位置无关并且具有单调性。题目https://leetcode.cn/submissions/detail/550154051/七0/1字符串问题1.前缀和解2.逆向思维转连续3.双指针(for两层循环的降级) https://leetcode.cn/problems/flip-string-to-monotone-increasing/4.保存差值。比如计算0和1数目相等路径不需要保存0有多少个1有多少个。而是报错0和1有值的diff反正就2个数比较https://leetcode.cn/problems/check-if-there-is-a-path-with-equal-number-of-0s-and-1s/solutions/2781653/2510-jian-cha-shi-fou-you-lu-jing-jing-g-wnwx/5.转换为固定的窗口的滑动窗口https://leetcode.cn/problems/minimum-swaps-to-group-all-1s-together-ii/solutions/1202043/zui-shao-jiao-huan-ci-shu-lai-zu-he-suo-iaghf/?envTypeweekly-questionenvId2026-02-15 0/1聚集就是把1整合在一起。求1的连续段。八动态规划划分字符串类如果是单字符串那么 dp[len]或者dp[from][to]如果是双字符串那么dp[len1][len2]遍历标准以该位置的元素为终点。算是这个范围的区间。或者https://leetcode.cn/problems/delete-operation-for-two-strings/ 这个遍历标准以该位置判断是否要带上这个元素。很像有区间的样子数组类如果是整体那么取整体如果影响1或者说有状态那么状态。如果说影响n可能是连续的https://leetcode.cn/problems/minimum-number-of-coins-for-fruits/submissions/572360725/遍历标准以该位置的元素为终点。是否accept该元素类似于两层for循环最长上升子序列和https://leetcode.cn/problems/non-overlapping-intervals/solutions/541543/wu-zhong-die-qu-jian-by-leetcode-solutio-cpsb/。遍历标准以该位置的元素为终点。状态类状态step类反向动态规划https://leetcode.cn/problems/knight-probability-in-chessboard/description/遍历标准以该时刻为状态。数学类几何形状堆叠动态规划https://leetcode.cn/problems/number-of-ways-to-build-house-of-cards/solutions/2848757/2189-jian-zao-zhi-pai-wu-de-fang-fa-shu-4uwx8/数学找规律https://leetcode.cn/problems/find-the-derangement-of-an-array/solutions/题目求总方法数一开始dp[0][0]1后面其他dp状态都是背包类0-1背包 遍历标准以数组长度为终点但不一定选。和数值作为dp。完全背包https://leetcode.cn/problems/coin-change/description/遍历标准以数值作为dp走台阶类走台阶不能重复https://leetcode.cn/problems/the-number-of-ways-to-make-the-sum/组合几何类长度 组合用3维dp表示有一定if条件的 https://leetcode.cn/problems/number-of-sets-of-k-non-overlapping-line-segments/solutions/450483/da-xiao-wei-k-de-bu-zhong-die-xian-duan-de-shu-mu-/树形dphttps://leetcode.cn/problems/U7WvvU/股票买卖ttps://leetcode.cn/problems/best-time-to-buy-and-sell-stock-v/solutions/3854340/mai-mai-gu-piao-de-zui-jia-shi-ji-v-by-l-di11/?envTypedaily-questionenvId2025-12-17遍历标准持有股票的状态和买卖次数类似股票买卖或者是打家劫舍啥的就是看起来我不能用线型规划做但实际可以拆分成2个状态做或者不做都是可以动态规划https://leetcode.cn/problems/minimum-increment-operations-to-make-array-beautiful/遍历标准是否持有只有一次动态规划动态规划描述路径如果是最长上升子序列由于是一维的直接用栈。若果是二维的https://leetcode.cn/problems/shortest-common-supersequence/solutions/3854855/cong-dpbiao-hui-su-gou-zao-by-hhczc-hj40/ 像这种那就根据数据双指针回溯。如果s[i] t[j]。那么必然回溯否则取走最大的路径。上面的动态规划都是代表我当前位置或者当前确定性的动态规划。第一种当前确定性动态规划意思是dp[i]代表就是我i本身持有一般这种就是走台阶或者是字符串连续第二种前缀性动态规划意思是dp[i]是之前累加一直到i本身也持有的一般这种为双重for循环或者是子字符串但非连续第三种递归性动态规划意思是我也不知道前面发生了什么但能确定我第i步做了操作。跟前缀性很像但这个维度遍历不是for循环了而是for循环去遍历动作状态。第四种就是股票买卖状态类动态规划https://leetcode.cn/problems/best-time-to-buy-and-sell-stock-v/solutions/3854340/mai-mai-gu-piao-de-zui-jia-shi-ji-v-by-l-di11/?envTypedaily-questionenvId2025-12-17。我不清楚是什么时候持有的但我现在的动作状态机就是要么持有要么没持有这样。九位运算https://leetcode.cn/circle/discuss/CaOJ45/https://leetcode.cn/submissions/detail/698864784/ 异或性质异或上0就是本身异或上自己就是0异或其他数一般只看最高位的1在哪个位置。十不用额外空间就地或者指针、位运算十一哈希表的key取法有时候枚举不会降低复杂度可以用差分、单位置转移。十二子序列两层for循环 dp或者根据长度动态规划https://leetcode.cn/problems/longest-palindromic-subsequence/solutions/转移公式为上一个长度。十三逆向思维法这种就属于问题编程法。数学https://leetcode.cn/problems/egg-drop-with-2-eggs-and-n-floors/solutions/2945577/liang-chong-fang-fa-dong-tai-gui-hua-shu-hd4i/?envTypedaily-questionenvId2024-10-13同为数学但是这个是遍历答案https://leetcode.cn/problems/minimum-operations-to-make-the-integer-zero/solutions/2319632/mei-ju-da-an-pythonjavacgo-by-endlessche-t4co/或者画一下函数等。十四数论/几何公因数https://leetcode.cn/problems/chou-shu-lcof/线性代数https://leetcode.cn/problems/maximum-linear-stock-score/solutions/2565409/2898-zui-da-xian-xing-gu-piao-de-fen-by-xkboe/摩尔投票法求n/3的个数 https://leetcode.cn/problems/majority-element-ii/solutions/1058790/qiu-zhong-shu-ii-by-leetcode-solution-y1rn/减一or除法https://leetcode.cn/problems/minimum-number-of-operations-to-make-x-and-y-equal/ 说明问题/5一定是-1或者1到临近的不可能是-1到下一个/5。举个例子在某操作中先减少了 7得到了 5 的倍数再除以 5显然不如先减少 2再除以 5再减少 1 划算后者节省了 4 步。凸多边形的性质https://leetcode.cn/submissions/detail/698909274/ 转角始终在同一顺序上不是小于90乘法逆元ab % mod 1模板https://leetcode.cn/problems/unit-conversion-ii/十五判断连通性并查集https://leetcode.cn/problems/redundant-connection/description/?envTypedaily-questionenvId2024-10-27十六集合遍历和排列组合https://leetcode.cn/problems/shopping-offers/?envTypedaily-questionenvId2024-11-03非01集合重复数字的排列组合https://leetcode.cn/problems/combination-sum-ii/十七c版本用set当做平衡二叉树https://leetcode.cn/problems/my-calendar-i/solutions/1643942/wo-de-ri-cheng-an-pai-biao-i-by-leetcode-nlxr/?envTypedaily-questionenvId2025-01-02还有双队列模拟比较复杂的用法https://leetcode.cn/problems/number-of-orders-in-the-backlog/solutions/2039856/ji-ya-ding-dan-zhong-de-ding-dan-zong-sh-6g22/十八多存多余的空间换时间除了自己之外的数据累计-双向遍历前缀https://leetcode.cn/problems/product-of-array-except-self/solutions/272369/chu-zi-shen-yi-wai-shu-zu-de-cheng-ji-by-leetcode-/十九空间复杂度o(1)一般要么就是像动态规划一样可迭代要么就是就地操作https://leetcode.cn/problems/product-of-array-except-self/solutions/272369/chu-zi-shen-yi-wai-shu-zu-de-cheng-ji-by-leetcode-/二十中位数中位数用双优先队列https://leetcode.cn/problems/minimum-operations-to-make-subarray-elements-equal/description/二十一区间范围/挤牛奶/模拟区间/重叠问题题掉落方块https://leetcode.cn/problems/falling-squares/https://leetcode.cn/problems/describe-the-painting/ 题目就是区间合并有好几种解法第一种差分数组直接数值当做区间来搞https://leetcode.cn/problems/describe-the-painting/solutions/894662/yi-bao-zhi-bao-yi-ba-suo-zhi-jie-lu-lian-hoty/ 这个是自己的题解。第二种排序优先队列https://leetcode.cn/problems/describe-the-painting/solutions/1090881/xiao-gen-dui-you-xian-dui-lie-klogkjie-f-eeyw/第三种线段树有人提了但是没实际MR二十二二叉树复杂的递归1.递归类似动态规划得到下一个确定性解当前不确定性https://leetcode.cn/problems/split-bst/solutions/2782550/776-chai-fen-er-cha-sou-suo-shu-by-storm-9sgw/二十三KMPhttps://leetcode.cn/problems/remove-all-occurrences-of-a-substring/solutions/847225/shan-chu-yi-ge-zi-fu-chuan-zhong-suo-you-4j08/学习点暴力也可以解可以用.erase或者string_view避免拷贝。并且kmp可以适用在栈操作删除字符串的场景上由于栈是对后状态无感知的所以可以用数组去保存跳转位置。二十八回文类快速生成数字回文https://leetcode.cn/problems/minimum-cost-to-make-array-equalindromic/solutions/2569308/yu-chu-li-hui-wen-shu-zhong-wei-shu-tan-7j0zy/ 思路不用字符串生成就是先生成半边的然后反转一下。二十九有点难度的图遍历岛屿洪水泛滥https://leetcode.cn/problems/number-of-closed-islands/solutions/?envTypeweekly-questionenvId2025-04-13 孤立岛屿类似并查集思想。三十有一点难的滑动窗口https://leetcode.cn/problems/count-complete-subarrays-in-an-array/solutions/3650491/tong-ji-wan-quan-zi-shu-zu-de-shu-mu-by-ysvhb/?envTypedaily-questionenvId2025-04-24 核心思想求包含了所有元素的子数目用另外一个变量acc代表前面有多少种可以允许的选择后续不断遍历。本质原因是单调递增。https://leetcode.cn/problems/count-of-interesting-subarrays/description/?envTypedaily-questionenvId2025-04-25 非单调递增的滑动窗口用%操作。跟上面的题类似但是更难这个时候不要用滑动窗口了也是涉及窗口左右扩展用前缀和。三十二约瑟夫环https://leetcode.cn/problems/elimination-game/solutions/1187589/gong-shui-san-xie-yue-se-fu-huan-yun-yon-x60m/?envTypeweekly-questionenvId2025-05-01 奇数偶数删除一直到最后一个数字三十三ACM算法-线段树专题https://leetcode.cn/problems/fruits-into-baskets-iii/solutions/3603049/xian-duan-shu-er-fen-pythonjavacgo-by-en-ssqf/ 水果成篮3-找到当前水果对应能放得下的篮子先从最左边开始找。核心解决思路主要是二分分块判断当前最大值是否值得找。线段树的话可以中序遍历解决找最左边的问题。否则是O(n^2)树上线段树https://leetcode.cn/problems/coin-bonus/ 树上区间修改区间查询三十四字典树文件系统https://leetcode.cn/problems/design-file-system/description/?envTypeweekly-questionenvId2025-08-10多次查找大字符串内小字符串对应https://leetcode.cn/problems/multi-search-lcci/solutions/137582/c-shuang-100-trie-tree-by-georgeljc/。主要思想合并查找。三十五优先队列优先队列自定义sort:https://blog.csdn.net/weixin_52115456/article/details/127606811优先队列内查找元素https://leetcode.cn/problems/design-a-food-rating-system/description/?envTypedaily-questionenvId2025-02-28优先队列增删改查(multiset): https://leetcode.cn/problems/132-pattern/solutions/676437/132mo-shi-by-leetcode-solution-ye89/上下车模型因为根据时间是正序的所以只用保存右端点与哪个队列无关https://leetcode.cn/problems/divide-intervals-into-minimum-number-of-groups/solutions/1816294/by-endlesscheng-ze3t/优先队列保存最大值和最小值https://leetcode.cn/problems/count-partitions-with-max-min-difference-at-most-k/solutions/3843928/tong-ji-ji-chai-zui-da-wei-k-de-fen-ge-f-spi4/?envTypedaily-questionenvId2025-12-06三十六字符串比较难的模拟题重复生成https://leetcode.cn/problems/decoded-string-at-index/description/?envTypeweekly-questionenvId2025-10-01 字符串会重复写n次要求你第k位的字母。字符串滚动哈希https://leetcode.cn/problems/strings-differ-by-one-character/solutions/本质就是前缀和可以用stringview来代替。字符串数字https://leetcode.cn/problems/monotone-increasing-digits/solutions/521694/dan-diao-di-zeng-de-shu-zi-by-leetcode-s-5908/ 核心思想 寻找最临近的单调递增的数字除了全部枚举二分也可用贪心。9为最大。然后依次减。之前美团考过的就是一个字符串前面删除k个后面补k个这种流式字符串解法https://leetcode.cn/problems/minimum-time-to-revert-word-to-initial-state-ii/description/https://leetcode.cn/problems/minimum-time-to-revert-word-to-initial-state-i/solutions/2631960/3029-jiang-dan-ci-hui-fu-chu-shi-zhuang-afq7h/?envTypeweekly-questionenvId2026-02-15。其实不需要考虑后面的字符加什么东西。三十七迪杰斯特拉变式题有限制可以去掉某一边权重然后求最小动态规划其实跟股票买卖有点一样https://leetcode.cn/problems/minimum-distance-excluding-one-maximum-weighted-edge/description/模板题迪杰斯特拉模板题https://leetcode.cn/problems/minimum-cost-to-buy-apples/description/并查集模板题https://leetcode.cn/submissions/detail/548115116/c map双层嵌套遍历https://leetcode.cn/problems/minimum-cost-to-buy-apples/description/拓扑排序模板题https://leetcode.cn/problems/employee-importance/description/?envTypedaily-questionenvId2024-08-26https://leetcode.cn/problems/find-all-possible-recipes-from-given-supplies/description/数位dphttps://leetcode.cn/problems/numbers-at-most-n-given-digit-set/solutions/1900101/shu-wei-dp-tong-yong-mo-ban-xiang-xi-zhu-e5dg/?envTypestudy-plan-v2envIdbytedance-2023-spring-sprint中缀转后缀求表达式的值最小堆https://leetcode.cn/problems/smallest-k-lcci/description/最小生成树https://leetcode.cn/problems/connecting-cities-with-minimum-cost/solutions/150694/zui-di-cheng-ben-lian-tong-suo-you-cheng-shi-by-le/?envTypeweekly-questionenvId2025-10-01C(n,m) 组合数https://leetcode.cn/problems/toss-strange-coins/二分方便apihttps://leetcode.cn/problems/number-of-perfect-pairs/https://leetcode.cn/problems/walking-robot-simulation/?envTypedaily-questionenvId2026-04-06ACM算法1、线段树线段树模板题https://leetcode.cn/problems/fancy-sequence/线段树 懒标记: https://leetcode.cn/problems/my-calendar-ii/solutions/1678660/wo-de-ri-cheng-an-pai-biao-ii-by-leetcod-wo6n/?envTypedaily-questionenvId2025-01-03区间修改区间查询https://leetcode.cn/problems/design-memory-allocator/solutions/2016010/bao-li-mo-ni-by-endlesscheng-bqba/?envTypedaily-questionenvId2025-02-25线段树求区间最大值https://leetcode.cn/problems/falling-squares/submissions/596004363/树状数组https://leetcode.cn/problems/find-the-index-of-permutation/用值去构建树状数组0为不存在1为存在。然后a[i]前缀和代表小于a[i]数的总数目https://leetcode.cn/problems/count-number-of-teams/solutions/186425/tong-ji-zuo-zhan-dan-wei-shu-by-leetcode-solution/下标从0开始的区间修改单点查询https://leetcode.cn/problems/range-addition/description/?envTypeweekly-questionenvId2025-11-23树上dphttps://leetcode.cn/problems/choose-edges-to-maximize-score-in-a-tree/solutions/1877272/by-goon-4-1cad/逆序对右边大于他的个数归并排序线段树https://leetcode.cn/problems/count-of-smaller-numbers-after-self/solutions/1308773/4chong-jie-fa-yi-wang-da-jin-pai-xu-shu-5vvds/?envTypeproblem-list-v2envIdsegment-tree学校老套路不同的二叉搜索树 - 卡特兰数 https://leetcode.cn/problems/unique-binary-search-trees/description/链表快排https://leetcode.cn/problems/convert-sorted-list-to-binary-search-tree/solutions/378582/you-xu-lian-biao-zhuan-huan-er-cha-sou-suo-shu-1-3/组合数动态规划或者用费马小定理快速求得https://blog.csdn.net/wan_guanghui/article/details/140816336一些比较好的思路顺着遍历再检查这个时间复杂度比较高我可以逆着遍历并填充cnthttps://leetcode.cn/problems/analyze-user-website-visit-pattern/?envTypeweekly-questionenvId2025-09-21字符串哈希代替字符串拼接https://leetcode.cn/problems/compare-version-numbers/solutions/970416/bi-jiao-ban-ben-hao-by-leetcode-solution-k6wi/?envTypedaily-questionenvId2025-09-23