个人刷算法题的做题笔记和心得,收录了个人认为典型或有趣的题目。
更新中... 2023
Bit Manipulation
-
2275. Largest Combination With Bitwise AND Greater Than Zero
-
2419. Longest Subarray With Maximum Bitwise AND (non-increasing means a[i] >= a[i + 1], non-decreasing is the same logic)
-
2397. Maximum Rows Covered by Columns (位运算遍历所有可能)
-
1734. Decode XORed Permutation (XOR运算的’交换律‘)
-
2564. Substring XOR Queries (XOR+常识)
-
1915. Number of Wonderful Substrings (preSum + bitmask)
-
1542. Find Longest Awesome Substring (bitmask + prefix)
-
2680. Maximum OR (bit OR)
-
2749. Minimum Operations to Make the Integer Zero (bit / brainteaser)
-
2772. Apply Operations to Make All Array Elements Equal to Zero (差分数组)
-
2857. Count Pairs of Points With Distance k (枚举 / thinking)
Array
-
42. Trapping Rain Water (DP/单调栈)
-
525. Contiguous Array * (preSum + hash)
-
452. Minimum Number of Arrows to Burst Balloons (interval类型题目)
-
53. Maximum Subarray (kadane/DP/分治法)
-
918. Maximum Sum Circular Subarray (kadane算法)
-
974. Subarray Sums Divisible by K (前缀和/Map)
-
2449. Minimum Number of Operations to Make Arrays Similar (Sort/Greedy)
-
2563. Count the Number of Fair Pairs (排序+two pointers/二分)
-
1871. Jump Game VII (preSum/sliding)
-
2584. Split the Array to Make Coprime Products (Array/Map)
-
2444. Count Subarrays With Fixed Bounds (Sliding Window / Subarray / Three Pointers)
-
2588. Count the Number of Beautiful Subarrays (XOR / preSum)
-
2589. Minimum Time to Complete All Tasks (Interval / Sorting / Greedy)
-
2597. The Number of Beautiful Subsets (Subset / Hash / Set / Math)
-
2607. Make K-Subarray Sums Equal (Circluar Array / Median)
-
2536. Increment Submatrices by One / LCP 74. 最强祝福力场 (离散化+二维差分)
-
2653. Sliding Subarray Beauty / 1419. Minimum Number of Frogs Croaking (Counting)
-
2718. Sum of Matrix After Queries (矩阵操作 / 倒序)
-
2731. Movement of Robots (robots碰撞 / 思维题)
-
1186. Maximum Subarray Sum with One Deletion (sliding window ? kadane!)
-
Codeforces Round 881 (Div.3) F1. Omsk Metro (simple version) (Kadane / DP)
-
2779. Maximum Beauty of an Array After Applying Operation (排序 + 滑动窗口 / 差分)
-
2842. Count K-Subsequences of a String With Maximum Beauty (组合数学C/A)
Binary Search
-
2517. Maximum Tastiness of Candy Basket (二分题型方法总结)
-
2513. Minimize the Maximum of Two Arrays (二分+集合计算)
-
2576. Find the Maximum Number of Marked Indices (二分+贪心 / 双指针)
-
2616. Minimize the Maximum Difference of Pairs (二分+贪心+数学归纳法)
-
1498. Number of Subsequences That Satisfy the Given Sum Condition / 1964. Find the Longest Valid Obstacle Course at Each Position (Binary Search in Array)
-
1760. Minimum Limit of Balls in a Bag (10^9二分后是多少?)
-
69. Sqrt(x) (某du外包题)
Top K
-
1383. Maximum Performance of a Team / 502. IPO (Heap/Sort)
-
2551. Put Marbles in Bags (两端数之和/Heap)
Linkedlist
Stack & Queue
-
85. Maximal Rectangle (单调栈/DP)
-
1856. Maximum Subarray Min-Product (Monotonic Stack单调栈 / 单调栈+贡献法汇总)
-
649. Dota2 Senate (Simulation + Queue)
-
735. Asteroid Collision & 2751. Robot Collisions (Stack / Movement)
-
2818. Apply Operations to Maximize Score (单调栈 + 贡献法 + 质因数 + 快速幂)
-
2866. Beautiful Towers II (单调栈 + 前后缀分解)
Sliding Window & Two Pointers
-
239. Sliding Window Maximum (堆/单调队列/分组预处理)
-
81. Search in Rotated Sorted Array II(Binary Search)
-
2401. Longest Nice Subarray (滑动窗口/位运算)
-
2537. Count the Number of Good Subarrays (滑动窗口/可逆向思维/子数组数量变化计算)
-
2234. Maximum Total Beauty of the Gardens (Sorting/Two Pointers)
-
1793. Maximum Score of a Good Subarray (Greedy + Two pointers)
-
2747. Count Zero Request Servers (Sort + Sliding Window)
-
1838. Frequency of the Most Frequent Element (Cnt + Greedy + Sliding Window)
-
719. Find K-th Smallest Pair Distance (Binary Search + Sliding Window)
String
-
2472. Maximum Number of Non-overlapping Palindrome Substrings (贪心+DP)
-
2484. Count Palindromic Subsequences (奇数次Palindromic String DP)
-
2663. Lexicographically Smallest Beautiful String (palindrome + greedy + 思维题)
BFS/DFS
-
2328. Number of Increasing Paths in a Grid (DFS+记忆化搜索/多源BFS+优先队列)
-
2503. Maximum Number of Points From Grid Queries (BFS+presum)
-
1976. Number of Ways to Arrive at Destination (BFS+PQ/Dijkstra)
-
1162. As Far from Land as Possible (BFS/DP)
-
2556. Disconnect Path in a Binary Matrix by at Most One Flip (DFS/路径覆盖)
-
1345. Jump Game IV (BFS in Array)
-
2612. Minimum Reverse Operations (BFS in Array / TreeSet)
-
934. Shortest Bridge (BFS/DFS/visited)
-
1631. Path With Minimum Effort (多源BFS)
Backtracking
-
212. Word Search II(Trie)
-
2698. Find the Punishment Number of an Integer (Backtracking + 预处理)
Greedy
-
2406. Divide Intervals Into Minimum Number of Groups (intervals/sort/greedy)
-
2434. Using a Robot to Print the Lexicographically Smallest String
-
2086. Minimum Number of Food Buckets to Feed the Hamsters (辐射)
-
2967. Minimum Cost to Make Array Equalindromic (Greedy + Math + Binary Search)
-
Codeforces Round 913 (Div.3) C. Removal of Unattractive Pairs (Greedy)
Tree
-
1443. Minimum Time to Collect All Apples in a Tree (多叉树的深度遍历)
-
124. Binary Tree Maximum Path Sum (树的path问题/dfs)
-
2385. Amount of Time for Binary Tree to Be Infected (同样是path问题/dfs)
-
2538. Difference Between Maximum and Minimum Price Sum (rerooting/DFS缓存)
-
968. Binary Tree Cameras (树状DP)
-
2581. Count Number of Possible Root Nodes (rerooting/twice DFS)
-
2603. Collect Coins in a Tree (Topological Sort 拓扑排序 总)
-
1026. Maximum Difference Between Node and Ancestor (递/归两种dfs)
-
2673. Make Costs of Paths Equal in a Binary Tree (树上DFS/归并贪心)
-
2858. Minimum Edge Reversals So Every Node Is Reachable (rerooting / 换根DP)
Graph
-
1584. Min Cost to Connect All Points (图的两种经典算法:Prim、Kruskal+UnionFind)
-
1192. Critical Connections in a Network(Tarjan algorithm)
-
1697. Checking Existence of Edge Length Limited Paths (树或图的path问题/Union Find 汇总)
-
2421. Number of Good Paths (树或图path问题/并查集+数学+排序连接)
-
2608. Shortest Cycle in a Graph / 2360. Longest Cycle in a Graph (无向图或有向图中的计算环长度问题/DFS或BFS)
-
2642. Design Graph With Shortest Path Calculator (有向权值图中两点最短路径)
-
1579. Remove Max Number of Edges to Keep Graph Fully Traversable (Union Find + 分类 + 删除/贪心)
-
2662. Minimum Cost of a Path With Special Roads (朴素Dijkstra)
-
2709. Greatest Common Divisor Traversal (素数筛 + 并查集)
-
1483. Kth Ancestor of a Tree Node / 2836. Maximize Value of Function in a Ball Passing Game (树上倍增)
-
2846. Minimum Edge Weight Equilibrium Queries in a Tree (LCA模版)
-
2876. Count Visited Nodes in a Directed Graph (内向基环树 / 拓扑排序)
-
2867. Count Valid Paths in a Tree (DFS / 并查集 / 染色)
DP
-
354. Russian Doll Envelopes(LIS问题)
-
646. Maximum Length of Pair Chain (LIS/Greedy)
-
474. Ones and Zeroes(DP解决subset问题)
-
2305. Fair Distribution of Cookies(状态压缩DP/用位表示)
-
2311. Longest Binary Subsequence Less Than or Equal to K (LIS)
-
2400. Number of Ways to Reach a Position After Exactly k Steps (在数轴上移动DP)
-
2518. Number of Great Partitions (coin change/knapsack背包)
-
926. Flip String to Monotone Increasing / 1653. Minimum Deletions to Make String Balanced (前缀和 / 01 string DP)
-
131. Palindrome Partitioning (Palindrome/DP/Backtrack)
-
2547. Minimum Cost to Split an Array (coin change的变型)
-
2552. Count Increasing Quadruplets (三元组/四元组/DP/元素在n范围内)
-
1626. Best Team With No Conflicts (Sorting/DP)
-
1727. Largest Submatrix With Rearrangements (Sorting/DP)
-
1911. Maximum Alternating Subsequence Sum (DP/Greedy)
-
123. Best Time to Buy and Sell Stock III / 2555. Maximize Win From Two Segments (DP/Sliding Window)
-
2054. Two Best Non-Overlapping Events / 1235. Maximum Profit in Job Scheduling (二分/自顶向下DP/记忆化搜索/)
-
2572. Count the Number of Square-Free Subsets (DP+bitmask)
-
1986. Minimum Number of Work Sessions to Finish the Tasks (DP+bitmask+dfs)
-
2585. Number of Ways to Earn Points (Knapsack / Limited Coin Change)
-
1012. Numbers With Repeated Digits (Digit DP 数位DP / Memorize Search / DFS)
-
1553. Minimum Number of Days to Eat N Oranges (Memoization+DFS 记忆化搜索)
-
2218. Maximum Value of K Coins From Piles (Top-down DP / Memoization)
-
1187. Make Array Strictly Increasing / 1043. Partition Array for Maximum Sum (Memoization -> DP 汇总)
-
940. Distinct Subsequences II / 1987. Number of Unique Good Subsequences (String Subsequences / DP / Ends)
-
2708. Maximum Strength of a Group (top-down dp + 乘法 / Greedy)
-
2712. Minimum Cost to Make All Characters Equal (01 String DP / Greedy)
-
2713. Maximum Strictly Increasing Cells in a Matrix (多源DP + 优先队列排序)
-
1262. Greatest Sum Divisible by Three (Greedy + Reverse / DP)
-
2741. Special Permutations (Permulation DP 全排列DP)
-
956. Tallest Billboard (Memoization DFS / DP)
-
2750. Ways to Split Array Into Good Subarrays (Greedy / DP)
-
2791. Count Paths That Can Form a Palindrome in a Tree (状压+前缀和哈希 / 树)
-
486. Predict the Winner / 464. Can I Win (Game Theory / DFS / Memoization)
-
2830. Maximize the Profit as the Salesman (二分DP / 同1235)
-
97. Interleaving String (自己重新做一遍)
Others
-
146. LRU Cache (LRU/LFU)
-
50. Pow(x, n) (2的倍数可以通过左移/右移位数来实现)
-
2280. Minimum Lines to Represent a Line Chart(double精度问题/最大公约数)
-
2402. Meeting Rooms III (模拟题)
-
2543. Check if Point Is Reachable (点能否到点的问题/找规律/数学)
-
1250. Check If It Is a Good Array (扩展欧几里得定理/裴蜀定理)