From e2bf4ac1a482ed3306197d10d53fcbcd8401a716 Mon Sep 17 00:00:00 2001 From: 2xiao <827574297wxxtb@sina.com> Date: Fri, 24 Jan 2025 00:16:48 +0800 Subject: [PATCH] add 15 solutions --- src/.vuepress/sidebar.ts | 15 ++ src/book/dynamic_programming.md | 6 +- src/book/graph.md | 2 +- src/plan/company_list.md | 2 +- src/plan/contest_list.md | 10 +- src/plan/rabbit_list.md | 2 +- src/plan/top_300_list.md | 8 +- src/problem/0042.md | 2 +- src/problem/0198.md | 2 +- src/problem/0207.md | 2 +- src/problem/0210.md | 2 +- src/problem/0213.md | 2 +- src/problem/0264.md | 2 +- src/problem/0306.md | 227 +++++++++++++++++++++++++++++ src/problem/0310.md | 192 +++++++++++++++++++++++++ src/problem/0313.md | 158 ++++++++++++++++++++ src/problem/0318.md | 145 +++++++++++++++++++ src/problem/0319.md | 153 ++++++++++++++++++++ src/problem/0331.md | 150 +++++++++++++++++++ src/problem/0337.md | 153 ++++++++++++++++++++ src/problem/0341.md | 184 ++++++++++++++++++++++++ src/problem/0357.md | 119 +++++++++++++++ src/problem/0407.md | 248 ++++++++++++++++++++++++++++++++ src/problem/1267.md | 174 ++++++++++++++++++++++ src/problem/1765.md | 218 ++++++++++++++++++++++++++++ src/problem/2017.md | 203 ++++++++++++++++++++++++++ src/problem/2133.md | 2 +- src/problem/2661.md | 177 +++++++++++++++++++++++ src/problem/2683.md | 185 ++++++++++++++++++++++++ src/problem/3203.md | 2 +- src/problem/README.md | 17 ++- src/tag/array.md | 6 +- src/tag/backtracking.md | 4 +- src/tag/binary-tree.md | 4 +- src/tag/bit-manipulation.md | 4 +- src/tag/brainteaser.md | 2 +- src/tag/breadth-first-search.md | 8 +- src/tag/counting.md | 2 +- src/tag/depth-first-search.md | 8 +- src/tag/design.md | 2 +- src/tag/dynamic-programming.md | 6 +- src/tag/graph.md | 2 +- src/tag/heap-priority-queue.md | 2 +- src/tag/iterator.md | 2 +- src/tag/math.md | 6 +- src/tag/matrix.md | 10 +- src/tag/prefix-sum.md | 2 +- src/tag/queue.md | 2 +- src/tag/stack.md | 4 +- src/tag/string.md | 6 +- src/tag/topological-sort.md | 2 +- src/tag/tree.md | 6 +- src/tag/union-find.md | 2 +- 53 files changed, 2786 insertions(+), 70 deletions(-) create mode 100644 src/problem/0306.md create mode 100644 src/problem/0310.md create mode 100644 src/problem/0313.md create mode 100644 src/problem/0318.md create mode 100644 src/problem/0319.md create mode 100644 src/problem/0331.md create mode 100644 src/problem/0337.md create mode 100644 src/problem/0341.md create mode 100644 src/problem/0357.md create mode 100644 src/problem/0407.md create mode 100644 src/problem/1267.md create mode 100644 src/problem/1765.md create mode 100644 src/problem/2017.md create mode 100644 src/problem/2661.md create mode 100644 src/problem/2683.md diff --git a/src/.vuepress/sidebar.ts b/src/.vuepress/sidebar.ts index 5dfd567f97..fa41d9d05a 100644 --- a/src/.vuepress/sidebar.ts +++ b/src/.vuepress/sidebar.ts @@ -278,14 +278,22 @@ export default sidebar({ "0300", "0303", "0304", + "0306", "0307", "0309", + "0310", + "0313", "0316", + "0318", + "0319", "0322", "0326", "0328", + "0331", "0334", + "0337", "0338", + "0341", "0342", "0343", "0344", @@ -296,6 +304,7 @@ export default sidebar({ "0350", "0354", "0355", + "0357", "0366", "0367", "0369", @@ -322,6 +331,7 @@ export default sidebar({ "0401", "0404", "0405", + "0407", "0409", "0412", "0414", @@ -624,6 +634,7 @@ export default sidebar({ "1252", "1260", "1266", + "1267", "1268", "1275", "1277", @@ -787,6 +798,7 @@ export default sidebar({ "1758", "1760", "1763", + "1765", "1768", "1769", "1773", @@ -865,6 +877,7 @@ export default sidebar({ "2006", "2011", "2016", + "2017", "2022", "2027", "2032", @@ -1050,12 +1063,14 @@ export default sidebar({ "2649", "2650", "2657", + "2661", "2665", "2666", "2667", "2675", "2676", "2677", + "2683", "2684", "2690", "2691", diff --git a/src/book/dynamic_programming.md b/src/book/dynamic_programming.md index 6526365efe..803bbd0e0c 100644 --- a/src/book/dynamic_programming.md +++ b/src/book/dynamic_programming.md @@ -231,7 +231,7 @@ | 1245 | 树的直径 🔒 | | [`树`](/tag/tree.md) [`深度优先搜索`](/tag/depth-first-search.md) [`广度优先搜索`](/tag/breadth-first-search.md) `2+` | 🟠 | [🀄️](https://leetcode.cn/problems/tree-diameter) [🔗](https://leetcode.com/problems/tree-diameter) | | 2246 | 相邻字符不同的最长路径 | | [`树`](/tag/tree.md) [`深度优先搜索`](/tag/depth-first-search.md) [`图`](/tag/graph.md) `3+` | 🔴 | [🀄️](https://leetcode.cn/problems/longest-path-with-different-adjacent-characters) [🔗](https://leetcode.com/problems/longest-path-with-different-adjacent-characters) | | 687 | 最长同值路径 | | [`树`](/tag/tree.md) [`深度优先搜索`](/tag/depth-first-search.md) [`二叉树`](/tag/binary-tree.md) | 🟠 | [🀄️](https://leetcode.cn/problems/longest-univalue-path) [🔗](https://leetcode.com/problems/longest-univalue-path) | -| 337 | 打家劫舍 III | | [`树`](/tag/tree.md) [`深度优先搜索`](/tag/depth-first-search.md) [`动态规划`](/tag/dynamic-programming.md) `1+` | 🟠 | [🀄️](https://leetcode.cn/problems/house-robber-iii) [🔗](https://leetcode.com/problems/house-robber-iii) | +| 337 | 打家劫舍 III | [[✓]](/problem/0337.md) | [`树`](/tag/tree.md) [`深度优先搜索`](/tag/depth-first-search.md) [`动态规划`](/tag/dynamic-programming.md) `1+` | 🟠 | [🀄️](https://leetcode.cn/problems/house-robber-iii) [🔗](https://leetcode.com/problems/house-robber-iii) | | 333 | 最大二叉搜索子树 🔒 | | [`树`](/tag/tree.md) [`深度优先搜索`](/tag/depth-first-search.md) [`二叉搜索树`](/tag/binary-search-tree.md) `2+` | 🟠 | [🀄️](https://leetcode.cn/problems/largest-bst-subtree) [🔗](https://leetcode.com/problems/largest-bst-subtree) | | 1617 | 统计子树中城市之间最大距离 | | [`位运算`](/tag/bit-manipulation.md) [`树`](/tag/tree.md) [`动态规划`](/tag/dynamic-programming.md) `2+` | 🔴 | [🀄️](https://leetcode.cn/problems/count-subtrees-with-max-distance-between-cities) [🔗](https://leetcode.com/problems/count-subtrees-with-max-distance-between-cities) | | 2538 | 最大价值和与最小价值和的差值 | | [`树`](/tag/tree.md) [`深度优先搜索`](/tag/depth-first-search.md) [`数组`](/tag/array.md) `1+` | 🔴 | [🀄️](https://leetcode.cn/problems/difference-between-maximum-and-minimum-price-sum) [🔗](https://leetcode.com/problems/difference-between-maximum-and-minimum-price-sum) | @@ -247,7 +247,7 @@ | 题号 | 标题 | 题解 | 标签 | 难度 | 力扣 | | :------: | :------ | :------: | :------ | :------: | :------: | -| 310 | 最小高度树 | | [`深度优先搜索`](/tag/depth-first-search.md) [`广度优先搜索`](/tag/breadth-first-search.md) [`图`](/tag/graph.md) `1+` | 🟠 | [🀄️](https://leetcode.cn/problems/minimum-height-trees) [🔗](https://leetcode.com/problems/minimum-height-trees) | +| 310 | 最小高度树 | [[✓]](/problem/0310.md) | [`深度优先搜索`](/tag/depth-first-search.md) [`广度优先搜索`](/tag/breadth-first-search.md) [`图`](/tag/graph.md) `1+` | 🟠 | [🀄️](https://leetcode.cn/problems/minimum-height-trees) [🔗](https://leetcode.com/problems/minimum-height-trees) | | 834 | 树中距离之和 | | [`树`](/tag/tree.md) [`深度优先搜索`](/tag/depth-first-search.md) [`图`](/tag/graph.md) `1+` | 🔴 | [🀄️](https://leetcode.cn/problems/sum-of-distances-in-tree) [🔗](https://leetcode.com/problems/sum-of-distances-in-tree) | | 2581 | 统计可能的树根数目 | | [`树`](/tag/tree.md) [`深度优先搜索`](/tag/depth-first-search.md) [`数组`](/tag/array.md) `2+` | 🔴 | [🀄️](https://leetcode.cn/problems/count-number-of-possible-root-nodes) [🔗](https://leetcode.com/problems/count-number-of-possible-root-nodes) | @@ -300,7 +300,7 @@ | 题号 | 标题 | 题解 | 标签 | 难度 | 力扣 | | :------: | :------ | :------: | :------ | :------: | :------: | | 2376 | 统计特殊整数 | | [`数学`](/tag/math.md) [`动态规划`](/tag/dynamic-programming.md) | 🔴 | [🀄️](https://leetcode.cn/problems/count-special-integers) [🔗](https://leetcode.com/problems/count-special-integers) | -| 357 | 统计各位数字都不同的数字个数 | | [`数学`](/tag/math.md) [`动态规划`](/tag/dynamic-programming.md) [`回溯`](/tag/backtracking.md) | 🟠 | [🀄️](https://leetcode.cn/problems/count-numbers-with-unique-digits) [🔗](https://leetcode.com/problems/count-numbers-with-unique-digits) | +| 357 | 统计各位数字都不同的数字个数 | [[✓]](/problem/0357.md) | [`数学`](/tag/math.md) [`动态规划`](/tag/dynamic-programming.md) [`回溯`](/tag/backtracking.md) | 🟠 | [🀄️](https://leetcode.cn/problems/count-numbers-with-unique-digits) [🔗](https://leetcode.com/problems/count-numbers-with-unique-digits) | | 1012 | 至少有 1 位重复的数字 | | [`数学`](/tag/math.md) [`动态规划`](/tag/dynamic-programming.md) | 🔴 | [🀄️](https://leetcode.cn/problems/numbers-with-repeated-digits) [🔗](https://leetcode.com/problems/numbers-with-repeated-digits) | | 902 | 最大为 N 的数字组合 | | [`数组`](/tag/array.md) [`数学`](/tag/math.md) [`字符串`](/tag/string.md) `2+` | 🔴 | [🀄️](https://leetcode.cn/problems/numbers-at-most-n-given-digit-set) [🔗](https://leetcode.com/problems/numbers-at-most-n-given-digit-set) | | 788 | 旋转数字 | | [`数学`](/tag/math.md) [`动态规划`](/tag/dynamic-programming.md) | 🟠 | [🀄️](https://leetcode.cn/problems/rotated-digits) [🔗](https://leetcode.com/problems/rotated-digits) | diff --git a/src/book/graph.md b/src/book/graph.md index 846e3a2bb7..7466a96262 100644 --- a/src/book/graph.md +++ b/src/book/graph.md @@ -96,7 +96,7 @@ | 题号 | 标题 | 题解 | 标签 | 难度 | 力扣 | | :------: | :------ | :------: | :------ | :------: | :------: | -| 407 | 接雨水 II | | [`广度优先搜索`](/tag/breadth-first-search.md) [`数组`](/tag/array.md) [`矩阵`](/tag/matrix.md) `1+` | 🔴 | [🀄️](https://leetcode.cn/problems/trapping-rain-water-ii) [🔗](https://leetcode.com/problems/trapping-rain-water-ii) | +| 407 | 接雨水 II | [[✓]](/problem/0407.md) | [`广度优先搜索`](/tag/breadth-first-search.md) [`数组`](/tag/array.md) [`矩阵`](/tag/matrix.md) `1+` | 🔴 | [🀄️](https://leetcode.cn/problems/trapping-rain-water-ii) [🔗](https://leetcode.com/problems/trapping-rain-water-ii) | | 743 | 网络延迟时间 | | [`深度优先搜索`](/tag/depth-first-search.md) [`广度优先搜索`](/tag/breadth-first-search.md) [`图`](/tag/graph.md) `2+` | 🟠 | [🀄️](https://leetcode.cn/problems/network-delay-time) [🔗](https://leetcode.com/problems/network-delay-time) | | 787 | K 站中转内最便宜的航班 | | [`深度优先搜索`](/tag/depth-first-search.md) [`广度优先搜索`](/tag/breadth-first-search.md) [`图`](/tag/graph.md) `3+` | 🟠 | [🀄️](https://leetcode.cn/problems/cheapest-flights-within-k-stops) [🔗](https://leetcode.com/problems/cheapest-flights-within-k-stops) | | 1631 | 最小体力消耗路径 | | [`深度优先搜索`](/tag/depth-first-search.md) [`广度优先搜索`](/tag/breadth-first-search.md) [`并查集`](/tag/union-find.md) `4+` | 🟠 | [🀄️](https://leetcode.cn/problems/path-with-minimum-effort) [🔗](https://leetcode.com/problems/path-with-minimum-effort) | diff --git a/src/plan/company_list.md b/src/plan/company_list.md index 91bea5962a..ff35bd6932 100644 --- a/src/plan/company_list.md +++ b/src/plan/company_list.md @@ -209,7 +209,7 @@ headerDepth: 0 | 987 | 二叉树的垂序遍历 | | [`树`](/tag/tree.md) [`深度优先搜索`](/tag/depth-first-search.md) [`广度优先搜索`](/tag/breadth-first-search.md) `3+` | 🔴 | [🀄️](https://leetcode.cn/problems/vertical-order-traversal-of-a-binary-tree) [🔗](https://leetcode.com/problems/vertical-order-traversal-of-a-binary-tree) | 9 | | 105 | 从前序与中序遍历序列构造二叉树 | [[✓]](/problem/0105.md) | [`树`](/tag/tree.md) [`数组`](/tag/array.md) [`哈希表`](/tag/hash-table.md) `2+` | 🟠 | [🀄️](https://leetcode.cn/problems/construct-binary-tree-from-preorder-and-inorder-traversal) [🔗](https://leetcode.com/problems/construct-binary-tree-from-preorder-and-inorder-traversal) | 9 | | 442 | 数组中重复的数据 | [[✓]](/problem/0442.md) | [`数组`](/tag/array.md) [`哈希表`](/tag/hash-table.md) | 🟠 | [🀄️](https://leetcode.cn/problems/find-all-duplicates-in-an-array) [🔗](https://leetcode.com/problems/find-all-duplicates-in-an-array) | 9 | -| 341 | 扁平化嵌套列表迭代器 | | [`栈`](/tag/stack.md) [`树`](/tag/tree.md) [`深度优先搜索`](/tag/depth-first-search.md) `3+` | 🟠 | [🀄️](https://leetcode.cn/problems/flatten-nested-list-iterator) [🔗](https://leetcode.com/problems/flatten-nested-list-iterator) | 8 | +| 341 | 扁平化嵌套列表迭代器 | [[✓]](/problem/0341.md) | [`栈`](/tag/stack.md) [`树`](/tag/tree.md) [`深度优先搜索`](/tag/depth-first-search.md) `3+` | 🟠 | [🀄️](https://leetcode.cn/problems/flatten-nested-list-iterator) [🔗](https://leetcode.com/problems/flatten-nested-list-iterator) | 8 | | 33 | 搜索旋转排序数组 | [[✓]](/problem/0033.md) | [`数组`](/tag/array.md) [`二分查找`](/tag/binary-search.md) | 🟠 | [🀄️](https://leetcode.cn/problems/search-in-rotated-sorted-array) [🔗](https://leetcode.com/problems/search-in-rotated-sorted-array) | 7 | | 487 | 最大连续1的个数 II 🔒 | | [`数组`](/tag/array.md) [`动态规划`](/tag/dynamic-programming.md) [`滑动窗口`](/tag/sliding-window.md) | 🟠 | [🀄️](https://leetcode.cn/problems/max-consecutive-ones-ii) [🔗](https://leetcode.com/problems/max-consecutive-ones-ii) | 1 | diff --git a/src/plan/contest_list.md b/src/plan/contest_list.md index 01e261b163..6246c0274c 100644 --- a/src/plan/contest_list.md +++ b/src/plan/contest_list.md @@ -1356,7 +1356,7 @@ headerDepth: 0 | 题号 | 标题 | 题解 | 标签 | 难度 | 力扣 | | :------: | :------ | :------: | :------ | :------: | :------: | | 2682 | 找出转圈游戏输家 | | [`数组`](/tag/array.md) [`哈希表`](/tag/hash-table.md) [`模拟`](/tag/simulation.md) | 🟢 | [🀄️](https://leetcode.cn/problems/find-the-losers-of-the-circular-game) [🔗](https://leetcode.com/problems/find-the-losers-of-the-circular-game) | -| 2683 | 相邻值的按位异或 | | [`位运算`](/tag/bit-manipulation.md) [`数组`](/tag/array.md) | 🟠 | [🀄️](https://leetcode.cn/problems/neighboring-bitwise-xor) [🔗](https://leetcode.com/problems/neighboring-bitwise-xor) | +| 2683 | 相邻值的按位异或 | [[✓]](/problem/2683.md) | [`位运算`](/tag/bit-manipulation.md) [`数组`](/tag/array.md) | 🟠 | [🀄️](https://leetcode.cn/problems/neighboring-bitwise-xor) [🔗](https://leetcode.com/problems/neighboring-bitwise-xor) | | 2684 | 矩阵中移动的最大次数 | [[✓]](/problem/2684.md) | [`数组`](/tag/array.md) [`动态规划`](/tag/dynamic-programming.md) [`矩阵`](/tag/matrix.md) | 🟠 | [🀄️](https://leetcode.cn/problems/maximum-number-of-moves-in-a-grid) [🔗](https://leetcode.com/problems/maximum-number-of-moves-in-a-grid) | | 2685 | 统计完全连通分量的数量 | | [`深度优先搜索`](/tag/depth-first-search.md) [`广度优先搜索`](/tag/breadth-first-search.md) [`图`](/tag/graph.md) | 🟠 | [🀄️](https://leetcode.cn/problems/count-the-number-of-complete-components) [🔗](https://leetcode.com/problems/count-the-number-of-complete-components) | @@ -1392,7 +1392,7 @@ headerDepth: 0 | 题号 | 标题 | 题解 | 标签 | 难度 | 力扣 | | :------: | :------ | :------: | :------ | :------: | :------: | | 2660 | 保龄球游戏的获胜者 | | [`数组`](/tag/array.md) [`模拟`](/tag/simulation.md) | 🟢 | [🀄️](https://leetcode.cn/problems/determine-the-winner-of-a-bowling-game) [🔗](https://leetcode.com/problems/determine-the-winner-of-a-bowling-game) | -| 2661 | 找出叠涂元素 | | [`数组`](/tag/array.md) [`哈希表`](/tag/hash-table.md) [`矩阵`](/tag/matrix.md) | 🟠 | [🀄️](https://leetcode.cn/problems/first-completely-painted-row-or-column) [🔗](https://leetcode.com/problems/first-completely-painted-row-or-column) | +| 2661 | 找出叠涂元素 | [[✓]](/problem/2661.md) | [`数组`](/tag/array.md) [`哈希表`](/tag/hash-table.md) [`矩阵`](/tag/matrix.md) | 🟠 | [🀄️](https://leetcode.cn/problems/first-completely-painted-row-or-column) [🔗](https://leetcode.com/problems/first-completely-painted-row-or-column) | | 2662 | 前往目标的最小代价 | | [`图`](/tag/graph.md) [`数组`](/tag/array.md) [`最短路`](/tag/shortest-path.md) `1+` | 🟠 | [🀄️](https://leetcode.cn/problems/minimum-cost-of-a-path-with-special-roads) [🔗](https://leetcode.com/problems/minimum-cost-of-a-path-with-special-roads) | | 2663 | 字典序最小的美丽字符串 | | [`贪心`](/tag/greedy.md) [`字符串`](/tag/string.md) | 🔴 | [🀄️](https://leetcode.cn/problems/lexicographically-smallest-beautiful-string) [🔗](https://leetcode.com/problems/lexicographically-smallest-beautiful-string) | @@ -2892,7 +2892,7 @@ headerDepth: 0 | 题号 | 标题 | 题解 | 标签 | 难度 | 力扣 | | :------: | :------ | :------: | :------ | :------: | :------: | | 2016 | 增量元素之间的最大差值 | [[✓]](/problem/2016.md) | [`数组`](/tag/array.md) | 🟢 | [🀄️](https://leetcode.cn/problems/maximum-difference-between-increasing-elements) [🔗](https://leetcode.com/problems/maximum-difference-between-increasing-elements) | -| 2017 | 网格游戏 | | [`数组`](/tag/array.md) [`矩阵`](/tag/matrix.md) [`前缀和`](/tag/prefix-sum.md) | 🟠 | [🀄️](https://leetcode.cn/problems/grid-game) [🔗](https://leetcode.com/problems/grid-game) | +| 2017 | 网格游戏 | [[✓]](/problem/2017.md) | [`数组`](/tag/array.md) [`矩阵`](/tag/matrix.md) [`前缀和`](/tag/prefix-sum.md) | 🟠 | [🀄️](https://leetcode.cn/problems/grid-game) [🔗](https://leetcode.com/problems/grid-game) | | 2018 | 判断单词是否能放入填字游戏内 | | [`数组`](/tag/array.md) [`枚举`](/tag/enumeration.md) [`矩阵`](/tag/matrix.md) | 🟠 | [🀄️](https://leetcode.cn/problems/check-if-word-can-be-placed-in-crossword) [🔗](https://leetcode.com/problems/check-if-word-can-be-placed-in-crossword) | | 2019 | 解出数学表达式的学生分数 | | [`栈`](/tag/stack.md) [`记忆化搜索`](/tag/memoization.md) [`数组`](/tag/array.md) `3+` | 🔴 | [🀄️](https://leetcode.cn/problems/the-score-of-students-solving-math-expression) [🔗](https://leetcode.com/problems/the-score-of-students-solving-math-expression) | @@ -3457,7 +3457,7 @@ headerDepth: 0 | :------: | :------ | :------: | :------ | :------: | :------: | | 1763 | 最长的美好子字符串 | [[✓]](/problem/1763.md) | [`位运算`](/tag/bit-manipulation.md) [`哈希表`](/tag/hash-table.md) [`字符串`](/tag/string.md) `2+` | 🟢 | [🀄️](https://leetcode.cn/problems/longest-nice-substring) [🔗](https://leetcode.com/problems/longest-nice-substring) | | 1764 | 通过连接另一个数组的子数组得到一个数组 | | [`贪心`](/tag/greedy.md) [`数组`](/tag/array.md) [`双指针`](/tag/two-pointers.md) `1+` | 🟠 | [🀄️](https://leetcode.cn/problems/form-array-by-concatenating-subarrays-of-another-array) [🔗](https://leetcode.com/problems/form-array-by-concatenating-subarrays-of-another-array) | -| 1765 | 地图中的最高点 | | [`广度优先搜索`](/tag/breadth-first-search.md) [`数组`](/tag/array.md) [`矩阵`](/tag/matrix.md) | 🟠 | [🀄️](https://leetcode.cn/problems/map-of-highest-peak) [🔗](https://leetcode.com/problems/map-of-highest-peak) | +| 1765 | 地图中的最高点 | [[✓]](/problem/1765.md) | [`广度优先搜索`](/tag/breadth-first-search.md) [`数组`](/tag/array.md) [`矩阵`](/tag/matrix.md) | 🟠 | [🀄️](https://leetcode.cn/problems/map-of-highest-peak) [🔗](https://leetcode.com/problems/map-of-highest-peak) | | 1766 | 互质树 | | [`树`](/tag/tree.md) [`深度优先搜索`](/tag/depth-first-search.md) [`数组`](/tag/array.md) `2+` | 🔴 | [🀄️](https://leetcode.cn/problems/tree-of-coprimes) [🔗](https://leetcode.com/problems/tree-of-coprimes) | @@ -4620,7 +4620,7 @@ headerDepth: 0 | 题号 | 标题 | 题解 | 标签 | 难度 | 力扣 | | :------: | :------ | :------: | :------ | :------: | :------: | | 1266 | 访问所有点的最小时间 | [[✓]](/problem/1266.md) | [`几何`](/tag/geometry.md) [`数组`](/tag/array.md) [`数学`](/tag/math.md) | 🟢 | [🀄️](https://leetcode.cn/problems/minimum-time-visiting-all-points) [🔗](https://leetcode.com/problems/minimum-time-visiting-all-points) | -| 1267 | 统计参与通信的服务器 | | [`深度优先搜索`](/tag/depth-first-search.md) [`广度优先搜索`](/tag/breadth-first-search.md) [`并查集`](/tag/union-find.md) `3+` | 🟠 | [🀄️](https://leetcode.cn/problems/count-servers-that-communicate) [🔗](https://leetcode.com/problems/count-servers-that-communicate) | +| 1267 | 统计参与通信的服务器 | [[✓]](/problem/1267.md) | [`深度优先搜索`](/tag/depth-first-search.md) [`广度优先搜索`](/tag/breadth-first-search.md) [`并查集`](/tag/union-find.md) `3+` | 🟠 | [🀄️](https://leetcode.cn/problems/count-servers-that-communicate) [🔗](https://leetcode.com/problems/count-servers-that-communicate) | | 1268 | 搜索推荐系统 | [[✓]](/problem/1268.md) | [`字典树`](/tag/trie.md) [`数组`](/tag/array.md) [`字符串`](/tag/string.md) `3+` | 🟠 | [🀄️](https://leetcode.cn/problems/search-suggestions-system) [🔗](https://leetcode.com/problems/search-suggestions-system) | | 1269 | 停在原地的方案数 | | [`动态规划`](/tag/dynamic-programming.md) | 🔴 | [🀄️](https://leetcode.cn/problems/number-of-ways-to-stay-in-the-same-place-after-some-steps) [🔗](https://leetcode.com/problems/number-of-ways-to-stay-in-the-same-place-after-some-steps) | diff --git a/src/plan/rabbit_list.md b/src/plan/rabbit_list.md index 9bfa62dccf..054856df3e 100644 --- a/src/plan/rabbit_list.md +++ b/src/plan/rabbit_list.md @@ -224,7 +224,7 @@ headerDepth: 0 | 460 | LFU 缓存 | [[✓]](/problem/0460.md) | [`设计`](/tag/design.md) [`哈希表`](/tag/hash-table.md) [`链表`](/tag/linked-list.md) `1+` | 🔴 | [🀄️](https://leetcode.cn/problems/lfu-cache) [🔗](https://leetcode.com/problems/lfu-cache) | 9 | | 442 | 数组中重复的数据 | [[✓]](/problem/0442.md) | [`数组`](/tag/array.md) [`哈希表`](/tag/hash-table.md) | 🟠 | [🀄️](https://leetcode.cn/problems/find-all-duplicates-in-an-array) [🔗](https://leetcode.com/problems/find-all-duplicates-in-an-array) | 9 | | 538 | 把二叉搜索树转换为累加树 | | [`树`](/tag/tree.md) [`深度优先搜索`](/tag/depth-first-search.md) [`二叉搜索树`](/tag/binary-search-tree.md) `1+` | 🟠 | [🀄️](https://leetcode.cn/problems/convert-bst-to-greater-tree) [🔗](https://leetcode.com/problems/convert-bst-to-greater-tree) | 8 | -| 341 | 扁平化嵌套列表迭代器 | | [`栈`](/tag/stack.md) [`树`](/tag/tree.md) [`深度优先搜索`](/tag/depth-first-search.md) `3+` | 🟠 | [🀄️](https://leetcode.cn/problems/flatten-nested-list-iterator) [🔗](https://leetcode.com/problems/flatten-nested-list-iterator) | 8 | +| 341 | 扁平化嵌套列表迭代器 | [[✓]](/problem/0341.md) | [`栈`](/tag/stack.md) [`树`](/tag/tree.md) [`深度优先搜索`](/tag/depth-first-search.md) `3+` | 🟠 | [🀄️](https://leetcode.cn/problems/flatten-nested-list-iterator) [🔗](https://leetcode.com/problems/flatten-nested-list-iterator) | 8 | | 2184 | 建造坚实的砖墙的方法数 🔒 | | [`位运算`](/tag/bit-manipulation.md) [`数组`](/tag/array.md) [`动态规划`](/tag/dynamic-programming.md) `1+` | 🟠 | [🀄️](https://leetcode.cn/problems/number-of-ways-to-build-sturdy-brick-wall) [🔗](https://leetcode.com/problems/number-of-ways-to-build-sturdy-brick-wall) | 8 | | 268 | 丢失的数字 | [[✓]](/problem/0268.md) | [`位运算`](/tag/bit-manipulation.md) [`数组`](/tag/array.md) [`哈希表`](/tag/hash-table.md) `3+` | 🟢 | [🀄️](https://leetcode.cn/problems/missing-number) [🔗](https://leetcode.com/problems/missing-number) | 8 | | 937 | 重新排列日志文件 | | [`数组`](/tag/array.md) [`字符串`](/tag/string.md) [`排序`](/tag/sorting.md) | 🟠 | [🀄️](https://leetcode.cn/problems/reorder-data-in-log-files) [🔗](https://leetcode.com/problems/reorder-data-in-log-files) | 7 | diff --git a/src/plan/top_300_list.md b/src/plan/top_300_list.md index 6ba02d3974..bd907bb5a4 100644 --- a/src/plan/top_300_list.md +++ b/src/plan/top_300_list.md @@ -193,7 +193,7 @@ headerDepth: 0 | 385 | 迷你语法分析器 | | [`栈`](/tag/stack.md) [`深度优先搜索`](/tag/depth-first-search.md) [`字符串`](/tag/string.md) | 🟠 | [🀄️](https://leetcode.cn/problems/mini-parser) [🔗](https://leetcode.com/problems/mini-parser) | | 1249 | 移除无效的括号 | | [`栈`](/tag/stack.md) [`字符串`](/tag/string.md) | 🟠 | [🀄️](https://leetcode.cn/problems/minimum-remove-to-make-valid-parentheses) [🔗](https://leetcode.com/problems/minimum-remove-to-make-valid-parentheses) | | 636 | 函数的独占时间 | | [`栈`](/tag/stack.md) [`数组`](/tag/array.md) | 🟠 | [🀄️](https://leetcode.cn/problems/exclusive-time-of-functions) [🔗](https://leetcode.com/problems/exclusive-time-of-functions) | -| 341 | 扁平化嵌套列表迭代器 | | [`栈`](/tag/stack.md) [`树`](/tag/tree.md) [`深度优先搜索`](/tag/depth-first-search.md) `3+` | 🟠 | [🀄️](https://leetcode.cn/problems/flatten-nested-list-iterator) [🔗](https://leetcode.com/problems/flatten-nested-list-iterator) | +| 341 | 扁平化嵌套列表迭代器 | [[✓]](/problem/0341.md) | [`栈`](/tag/stack.md) [`树`](/tag/tree.md) [`深度优先搜索`](/tag/depth-first-search.md) `3+` | 🟠 | [🀄️](https://leetcode.cn/problems/flatten-nested-list-iterator) [🔗](https://leetcode.com/problems/flatten-nested-list-iterator) | | 224 | 基本计算器 | [[✓]](/problem/0224.md) | [`栈`](/tag/stack.md) [`递归`](/tag/recursion.md) [`数学`](/tag/math.md) `1+` | 🔴 | [🀄️](https://leetcode.cn/problems/basic-calculator) [🔗](https://leetcode.com/problems/basic-calculator) | | 726 | 原子的数量 | | [`栈`](/tag/stack.md) [`哈希表`](/tag/hash-table.md) [`字符串`](/tag/string.md) `1+` | 🔴 | [🀄️](https://leetcode.cn/problems/number-of-atoms) [🔗](https://leetcode.com/problems/number-of-atoms) | @@ -357,7 +357,7 @@ headerDepth: 0 | 53 | 最大子数组和 | [[✓]](/problem/0053.md) | [`数组`](/tag/array.md) [`分治`](/tag/divide-and-conquer.md) [`动态规划`](/tag/dynamic-programming.md) | 🟠 | [🀄️](https://leetcode.cn/problems/maximum-subarray) [🔗](https://leetcode.com/problems/maximum-subarray) | | 121 | 买卖股票的最佳时机 | [[✓]](/problem/0121.md) | [`数组`](/tag/array.md) [`动态规划`](/tag/dynamic-programming.md) | 🟢 | [🀄️](https://leetcode.cn/problems/best-time-to-buy-and-sell-stock) [🔗](https://leetcode.com/problems/best-time-to-buy-and-sell-stock) | | 746 | 使用最小花费爬楼梯 | [[✓]](/problem/0746.md) | [`数组`](/tag/array.md) [`动态规划`](/tag/dynamic-programming.md) | 🟢 | [🀄️](https://leetcode.cn/problems/min-cost-climbing-stairs) [🔗](https://leetcode.com/problems/min-cost-climbing-stairs) | -| 337 | 打家劫舍 III | | [`树`](/tag/tree.md) [`深度优先搜索`](/tag/depth-first-search.md) [`动态规划`](/tag/dynamic-programming.md) `1+` | 🟠 | [🀄️](https://leetcode.cn/problems/house-robber-iii) [🔗](https://leetcode.com/problems/house-robber-iii) | +| 337 | 打家劫舍 III | [[✓]](/problem/0337.md) | [`树`](/tag/tree.md) [`深度优先搜索`](/tag/depth-first-search.md) [`动态规划`](/tag/dynamic-programming.md) `1+` | 🟠 | [🀄️](https://leetcode.cn/problems/house-robber-iii) [🔗](https://leetcode.com/problems/house-robber-iii) | | 322 | 零钱兑换 | [[✓]](/problem/0322.md) | [`广度优先搜索`](/tag/breadth-first-search.md) [`数组`](/tag/array.md) [`动态规划`](/tag/dynamic-programming.md) | 🟠 | [🀄️](https://leetcode.cn/problems/coin-change) [🔗](https://leetcode.com/problems/coin-change) | | 300 | 最长递增子序列 | [[✓]](/problem/0300.md) | [`数组`](/tag/array.md) [`二分查找`](/tag/binary-search.md) [`动态规划`](/tag/dynamic-programming.md) | 🟠 | [🀄️](https://leetcode.cn/problems/longest-increasing-subsequence) [🔗](https://leetcode.com/problems/longest-increasing-subsequence) | | 139 | 单词拆分 | [[✓]](/problem/0139.md) | [`字典树`](/tag/trie.md) [`记忆化搜索`](/tag/memoization.md) [`数组`](/tag/array.md) `3+` | 🟠 | [🀄️](https://leetcode.cn/problems/word-break) [🔗](https://leetcode.com/problems/word-break) | @@ -480,7 +480,7 @@ headerDepth: 0 | 706 | 设计哈希映射 | [[✓]](/problem/0706.md) | [`设计`](/tag/design.md) [`数组`](/tag/array.md) [`哈希表`](/tag/hash-table.md) `2+` | 🟢 | [🀄️](https://leetcode.cn/problems/design-hashmap) [🔗](https://leetcode.com/problems/design-hashmap) | | 703 | 数据流中的第 K 大元素 | [[✓]](/problem/0703.md) | [`树`](/tag/tree.md) [`设计`](/tag/design.md) [`二叉搜索树`](/tag/binary-search-tree.md) `3+` | 🟢 | [🀄️](https://leetcode.cn/problems/kth-largest-element-in-a-stream) [🔗](https://leetcode.com/problems/kth-largest-element-in-a-stream) | | 146 | LRU 缓存 | [[✓]](/problem/0146.md) | [`设计`](/tag/design.md) [`哈希表`](/tag/hash-table.md) [`链表`](/tag/linked-list.md) `1+` | 🟠 | [🀄️](https://leetcode.cn/problems/lru-cache) [🔗](https://leetcode.com/problems/lru-cache) | -| 341 | 扁平化嵌套列表迭代器 | | [`栈`](/tag/stack.md) [`树`](/tag/tree.md) [`深度优先搜索`](/tag/depth-first-search.md) `3+` | 🟠 | [🀄️](https://leetcode.cn/problems/flatten-nested-list-iterator) [🔗](https://leetcode.com/problems/flatten-nested-list-iterator) | +| 341 | 扁平化嵌套列表迭代器 | [[✓]](/problem/0341.md) | [`栈`](/tag/stack.md) [`树`](/tag/tree.md) [`深度优先搜索`](/tag/depth-first-search.md) `3+` | 🟠 | [🀄️](https://leetcode.cn/problems/flatten-nested-list-iterator) [🔗](https://leetcode.com/problems/flatten-nested-list-iterator) | | 208 | 实现 Trie (前缀树) | [[✓]](/problem/0208.md) | [`设计`](/tag/design.md) [`字典树`](/tag/trie.md) [`哈希表`](/tag/hash-table.md) `1+` | 🟠 | [🀄️](https://leetcode.cn/problems/implement-trie-prefix-tree) [🔗](https://leetcode.com/problems/implement-trie-prefix-tree) | | 173 | 二叉搜索树迭代器 | [[✓]](/problem/0173.md) | [`栈`](/tag/stack.md) [`树`](/tag/tree.md) [`设计`](/tag/design.md) `3+` | 🟠 | [🀄️](https://leetcode.cn/problems/binary-search-tree-iterator) [🔗](https://leetcode.com/problems/binary-search-tree-iterator) | | 622 | 设计循环队列 | [[✓]](/problem/0622.md) | [`设计`](/tag/design.md) [`队列`](/tag/queue.md) [`数组`](/tag/array.md) `1+` | 🟠 | [🀄️](https://leetcode.cn/problems/design-circular-queue) [🔗](https://leetcode.com/problems/design-circular-queue) | @@ -499,7 +499,7 @@ headerDepth: 0 | 946 | 验证栈序列 | [[✓]](/problem/0946.md) | [`栈`](/tag/stack.md) [`数组`](/tag/array.md) [`模拟`](/tag/simulation.md) | 🟠 | [🀄️](https://leetcode.cn/problems/validate-stack-sequences) [🔗](https://leetcode.com/problems/validate-stack-sequences) | | 767 | 重构字符串 | | [`贪心`](/tag/greedy.md) [`哈希表`](/tag/hash-table.md) [`字符串`](/tag/string.md) `3+` | 🟠 | [🀄️](https://leetcode.cn/problems/reorganize-string) [🔗](https://leetcode.com/problems/reorganize-string) | | 373 | 查找和最小的 K 对数字 | [[✓]](/problem/0373.md) | [`数组`](/tag/array.md) [`堆(优先队列)`](/tag/heap-priority-queue.md) | 🟠 | [🀄️](https://leetcode.cn/problems/find-k-pairs-with-smallest-sums) [🔗](https://leetcode.com/problems/find-k-pairs-with-smallest-sums) | -| 313 | 超级丑数 | | [`数组`](/tag/array.md) [`数学`](/tag/math.md) [`动态规划`](/tag/dynamic-programming.md) | 🟠 | [🀄️](https://leetcode.cn/problems/super-ugly-number) [🔗](https://leetcode.com/problems/super-ugly-number) | +| 313 | 超级丑数 | [[✓]](/problem/0313.md) | [`数组`](/tag/array.md) [`数学`](/tag/math.md) [`动态规划`](/tag/dynamic-programming.md) | 🟠 | [🀄️](https://leetcode.cn/problems/super-ugly-number) [🔗](https://leetcode.com/problems/super-ugly-number) | ## 回溯 diff --git a/src/problem/0042.md b/src/problem/0042.md index 9a7603a9da..6db7b9a687 100644 --- a/src/problem/0042.md +++ b/src/problem/0042.md @@ -166,6 +166,6 @@ var trap = function (height) { | :------: | :------ | :------: | :------ | :------: | :------: | | 11 | 盛最多水的容器 | [[✓]](/problem/0011.md) | [`贪心`](/tag/greedy.md) [`数组`](/tag/array.md) [`双指针`](/tag/two-pointers.md) | 🟠 | [🀄️](https://leetcode.cn/problems/container-with-most-water) [🔗](https://leetcode.com/problems/container-with-most-water) | | 238 | 除自身以外数组的乘积 | [[✓]](/problem/0238.md) | [`数组`](/tag/array.md) [`前缀和`](/tag/prefix-sum.md) | 🟠 | [🀄️](https://leetcode.cn/problems/product-of-array-except-self) [🔗](https://leetcode.com/problems/product-of-array-except-self) | -| 407 | 接雨水 II | | [`广度优先搜索`](/tag/breadth-first-search.md) [`数组`](/tag/array.md) [`矩阵`](/tag/matrix.md) `1+` | 🔴 | [🀄️](https://leetcode.cn/problems/trapping-rain-water-ii) [🔗](https://leetcode.com/problems/trapping-rain-water-ii) | +| 407 | 接雨水 II | [[✓]](/problem/0407.md) | [`广度优先搜索`](/tag/breadth-first-search.md) [`数组`](/tag/array.md) [`矩阵`](/tag/matrix.md) `1+` | 🔴 | [🀄️](https://leetcode.cn/problems/trapping-rain-water-ii) [🔗](https://leetcode.com/problems/trapping-rain-water-ii) | | 755 | 倒水 🔒 | | [`数组`](/tag/array.md) [`模拟`](/tag/simulation.md) | 🟠 | [🀄️](https://leetcode.cn/problems/pour-water) [🔗](https://leetcode.com/problems/pour-water) | | 2874 | 有序三元组中的最大值 II | | [`数组`](/tag/array.md) | 🟠 | [🀄️](https://leetcode.cn/problems/maximum-value-of-an-ordered-triplet-ii) [🔗](https://leetcode.com/problems/maximum-value-of-an-ordered-triplet-ii) | \ No newline at end of file diff --git a/src/problem/0198.md b/src/problem/0198.md index b5257209a9..30c601fd32 100644 --- a/src/problem/0198.md +++ b/src/problem/0198.md @@ -161,7 +161,7 @@ var rob = function (nums) { | 213 | 打家劫舍 II | [[✓]](/problem/0213.md) | [`数组`](/tag/array.md) [`动态规划`](/tag/dynamic-programming.md) | 🟠 | [🀄️](https://leetcode.cn/problems/house-robber-ii) [🔗](https://leetcode.com/problems/house-robber-ii) | | 256 | 粉刷房子 🔒 | | [`数组`](/tag/array.md) [`动态规划`](/tag/dynamic-programming.md) | 🟠 | [🀄️](https://leetcode.cn/problems/paint-house) [🔗](https://leetcode.com/problems/paint-house) | | 276 | 栅栏涂色 🔒 | | [`动态规划`](/tag/dynamic-programming.md) | 🟠 | [🀄️](https://leetcode.cn/problems/paint-fence) [🔗](https://leetcode.com/problems/paint-fence) | -| 337 | 打家劫舍 III | | [`树`](/tag/tree.md) [`深度优先搜索`](/tag/depth-first-search.md) [`动态规划`](/tag/dynamic-programming.md) `1+` | 🟠 | [🀄️](https://leetcode.cn/problems/house-robber-iii) [🔗](https://leetcode.com/problems/house-robber-iii) | +| 337 | 打家劫舍 III | [[✓]](/problem/0337.md) | [`树`](/tag/tree.md) [`深度优先搜索`](/tag/depth-first-search.md) [`动态规划`](/tag/dynamic-programming.md) `1+` | 🟠 | [🀄️](https://leetcode.cn/problems/house-robber-iii) [🔗](https://leetcode.com/problems/house-robber-iii) | | 600 | 不含连续1的非负整数 | | [`动态规划`](/tag/dynamic-programming.md) | 🔴 | [🀄️](https://leetcode.cn/problems/non-negative-integers-without-consecutive-ones) [🔗](https://leetcode.com/problems/non-negative-integers-without-consecutive-ones) | | 656 | 成本最小路径 🔒 | | [`数组`](/tag/array.md) [`动态规划`](/tag/dynamic-programming.md) | 🔴 | [🀄️](https://leetcode.cn/problems/coin-path) [🔗](https://leetcode.com/problems/coin-path) | | 740 | 删除并获得点数 | | [`数组`](/tag/array.md) [`哈希表`](/tag/hash-table.md) [`动态规划`](/tag/dynamic-programming.md) | 🟠 | [🀄️](https://leetcode.cn/problems/delete-and-earn) [🔗](https://leetcode.com/problems/delete-and-earn) | diff --git a/src/problem/0207.md b/src/problem/0207.md index fac0588204..2cce26f03a 100644 --- a/src/problem/0207.md +++ b/src/problem/0207.md @@ -143,6 +143,6 @@ var canFinish = function (numCourses, prerequisites) { | :------: | :------ | :------: | :------ | :------: | :------: | | 210 | 课程表 II | [[✓]](/problem/0210.md) | [`深度优先搜索`](/tag/depth-first-search.md) [`广度优先搜索`](/tag/breadth-first-search.md) [`图`](/tag/graph.md) `1+` | 🟠 | [🀄️](https://leetcode.cn/problems/course-schedule-ii) [🔗](https://leetcode.com/problems/course-schedule-ii) | | 261 | 以图判树 🔒 | | [`深度优先搜索`](/tag/depth-first-search.md) [`广度优先搜索`](/tag/breadth-first-search.md) [`并查集`](/tag/union-find.md) `1+` | 🟠 | [🀄️](https://leetcode.cn/problems/graph-valid-tree) [🔗](https://leetcode.com/problems/graph-valid-tree) | -| 310 | 最小高度树 | | [`深度优先搜索`](/tag/depth-first-search.md) [`广度优先搜索`](/tag/breadth-first-search.md) [`图`](/tag/graph.md) `1+` | 🟠 | [🀄️](https://leetcode.cn/problems/minimum-height-trees) [🔗](https://leetcode.com/problems/minimum-height-trees) | +| 310 | 最小高度树 | [[✓]](/problem/0310.md) | [`深度优先搜索`](/tag/depth-first-search.md) [`广度优先搜索`](/tag/breadth-first-search.md) [`图`](/tag/graph.md) `1+` | 🟠 | [🀄️](https://leetcode.cn/problems/minimum-height-trees) [🔗](https://leetcode.com/problems/minimum-height-trees) | | 630 | 课程表 III | | [`贪心`](/tag/greedy.md) [`数组`](/tag/array.md) [`排序`](/tag/sorting.md) `1+` | 🔴 | [🀄️](https://leetcode.cn/problems/course-schedule-iii) [🔗](https://leetcode.com/problems/course-schedule-iii) | | 2392 | 给定条件下构造矩阵 | | [`图`](/tag/graph.md) [`拓扑排序`](/tag/topological-sort.md) [`数组`](/tag/array.md) `1+` | 🔴 | [🀄️](https://leetcode.cn/problems/build-a-matrix-with-conditions) [🔗](https://leetcode.com/problems/build-a-matrix-with-conditions) | \ No newline at end of file diff --git a/src/problem/0210.md b/src/problem/0210.md index 38aa9aa1de..c3f7182541 100644 --- a/src/problem/0210.md +++ b/src/problem/0210.md @@ -163,7 +163,7 @@ var findOrder = function (numCourses, prerequisites) { | :------: | :------ | :------: | :------ | :------: | :------: | | 207 | 课程表 | [[✓]](/problem/0207.md) | [`深度优先搜索`](/tag/depth-first-search.md) [`广度优先搜索`](/tag/breadth-first-search.md) [`图`](/tag/graph.md) `1+` | 🟠 | [🀄️](https://leetcode.cn/problems/course-schedule) [🔗](https://leetcode.com/problems/course-schedule) | | 269 | 火星词典 🔒 | | [`深度优先搜索`](/tag/depth-first-search.md) [`广度优先搜索`](/tag/breadth-first-search.md) [`图`](/tag/graph.md) `3+` | 🔴 | [🀄️](https://leetcode.cn/problems/alien-dictionary) [🔗](https://leetcode.com/problems/alien-dictionary) | -| 310 | 最小高度树 | | [`深度优先搜索`](/tag/depth-first-search.md) [`广度优先搜索`](/tag/breadth-first-search.md) [`图`](/tag/graph.md) `1+` | 🟠 | [🀄️](https://leetcode.cn/problems/minimum-height-trees) [🔗](https://leetcode.com/problems/minimum-height-trees) | +| 310 | 最小高度树 | [[✓]](/problem/0310.md) | [`深度优先搜索`](/tag/depth-first-search.md) [`广度优先搜索`](/tag/breadth-first-search.md) [`图`](/tag/graph.md) `1+` | 🟠 | [🀄️](https://leetcode.cn/problems/minimum-height-trees) [🔗](https://leetcode.com/problems/minimum-height-trees) | | 444 | 序列重建 🔒 | | [`图`](/tag/graph.md) [`拓扑排序`](/tag/topological-sort.md) [`数组`](/tag/array.md) | 🟠 | [🀄️](https://leetcode.cn/problems/sequence-reconstruction) [🔗](https://leetcode.com/problems/sequence-reconstruction) | | 630 | 课程表 III | | [`贪心`](/tag/greedy.md) [`数组`](/tag/array.md) [`排序`](/tag/sorting.md) `1+` | 🔴 | [🀄️](https://leetcode.cn/problems/course-schedule-iii) [🔗](https://leetcode.com/problems/course-schedule-iii) | | 1136 | 并行课程 🔒 | | [`图`](/tag/graph.md) [`拓扑排序`](/tag/topological-sort.md) | 🟠 | [🀄️](https://leetcode.cn/problems/parallel-courses) [🔗](https://leetcode.com/problems/parallel-courses) | diff --git a/src/problem/0213.md b/src/problem/0213.md index e5d52dd779..37f2714e8c 100644 --- a/src/problem/0213.md +++ b/src/problem/0213.md @@ -169,6 +169,6 @@ var rob = function (nums) { | 198 | 打家劫舍 | [[✓]](/problem/0198.md) | [`数组`](/tag/array.md) [`动态规划`](/tag/dynamic-programming.md) | 🟠 | [🀄️](https://leetcode.cn/problems/house-robber) [🔗](https://leetcode.com/problems/house-robber) | | 256 | 粉刷房子 🔒 | | [`数组`](/tag/array.md) [`动态规划`](/tag/dynamic-programming.md) | 🟠 | [🀄️](https://leetcode.cn/problems/paint-house) [🔗](https://leetcode.com/problems/paint-house) | | 276 | 栅栏涂色 🔒 | | [`动态规划`](/tag/dynamic-programming.md) | 🟠 | [🀄️](https://leetcode.cn/problems/paint-fence) [🔗](https://leetcode.com/problems/paint-fence) | -| 337 | 打家劫舍 III | | [`树`](/tag/tree.md) [`深度优先搜索`](/tag/depth-first-search.md) [`动态规划`](/tag/dynamic-programming.md) `1+` | 🟠 | [🀄️](https://leetcode.cn/problems/house-robber-iii) [🔗](https://leetcode.com/problems/house-robber-iii) | +| 337 | 打家劫舍 III | [[✓]](/problem/0337.md) | [`树`](/tag/tree.md) [`深度优先搜索`](/tag/depth-first-search.md) [`动态规划`](/tag/dynamic-programming.md) `1+` | 🟠 | [🀄️](https://leetcode.cn/problems/house-robber-iii) [🔗](https://leetcode.com/problems/house-robber-iii) | | 600 | 不含连续1的非负整数 | | [`动态规划`](/tag/dynamic-programming.md) | 🔴 | [🀄️](https://leetcode.cn/problems/non-negative-integers-without-consecutive-ones) [🔗](https://leetcode.com/problems/non-negative-integers-without-consecutive-ones) | | 656 | 成本最小路径 🔒 | | [`数组`](/tag/array.md) [`动态规划`](/tag/dynamic-programming.md) | 🔴 | [🀄️](https://leetcode.cn/problems/coin-path) [🔗](https://leetcode.com/problems/coin-path) | \ No newline at end of file diff --git a/src/problem/0264.md b/src/problem/0264.md index cb5bb4ae95..18dab7fd7c 100644 --- a/src/problem/0264.md +++ b/src/problem/0264.md @@ -122,5 +122,5 @@ var nthUglyNumber = function (n) { | 204 | 计数质数 | [[✓]](/problem/0204.md) | [`数组`](/tag/array.md) [`数学`](/tag/math.md) [`枚举`](/tag/enumeration.md) `1+` | 🟠 | [🀄️](https://leetcode.cn/problems/count-primes) [🔗](https://leetcode.com/problems/count-primes) | | 263 | 丑数 | [[✓]](/problem/0263.md) | [`数学`](/tag/math.md) | 🟢 | [🀄️](https://leetcode.cn/problems/ugly-number) [🔗](https://leetcode.com/problems/ugly-number) | | 279 | 完全平方数 | [[✓]](/problem/0279.md) | [`广度优先搜索`](/tag/breadth-first-search.md) [`数学`](/tag/math.md) [`动态规划`](/tag/dynamic-programming.md) | 🟠 | [🀄️](https://leetcode.cn/problems/perfect-squares) [🔗](https://leetcode.com/problems/perfect-squares) | -| 313 | 超级丑数 | | [`数组`](/tag/array.md) [`数学`](/tag/math.md) [`动态规划`](/tag/dynamic-programming.md) | 🟠 | [🀄️](https://leetcode.cn/problems/super-ugly-number) [🔗](https://leetcode.com/problems/super-ugly-number) | +| 313 | 超级丑数 | [[✓]](/problem/0313.md) | [`数组`](/tag/array.md) [`数学`](/tag/math.md) [`动态规划`](/tag/dynamic-programming.md) | 🟠 | [🀄️](https://leetcode.cn/problems/super-ugly-number) [🔗](https://leetcode.com/problems/super-ugly-number) | | 1201 | 丑数 III | | [`数学`](/tag/math.md) [`二分查找`](/tag/binary-search.md) [`组合数学`](/tag/combinatorics.md) `1+` | 🟠 | [🀄️](https://leetcode.cn/problems/ugly-number-iii) [🔗](https://leetcode.com/problems/ugly-number-iii) | \ No newline at end of file diff --git a/src/problem/0306.md b/src/problem/0306.md new file mode 100644 index 0000000000..c7dfa2824e --- /dev/null +++ b/src/problem/0306.md @@ -0,0 +1,227 @@ +--- +title: 306. 累加数 +description: LeetCode 306. 累加数题解,Additive Number,包含解题思路、复杂度分析以及完整的 JavaScript 代码实现。 +keywords: + - LeetCode + - 306. 累加数 + - 累加数 + - Additive Number + - 解题思路 + - 字符串 + - 回溯 +--- + +# 306. 累加数 + +🟠 Medium  🔖  [`字符串`](/tag/string.md) [`回溯`](/tag/backtracking.md)  🔗 [`力扣`](https://leetcode.cn/problems/additive-number) [`LeetCode`](https://leetcode.com/problems/additive-number) + +## 题目 + +An **additive number** is a string whose digits can form an **additive sequence**. + +A valid **additive sequence** should contain **at least** three numbers. +Except for the first two numbers, each subsequent number in the sequence must +be the sum of the preceding two. + +Given a string containing only digits, return `true` if it is an **additive +number** or `false` otherwise. + +**Note:** Numbers in the additive sequence **cannot** have leading zeros, so +sequence `1, 2, 03` or `1, 02, 3` is invalid. + +**Example 1:** + +> Input: "112358" +> +> Output: true +> +> Explanation: +> +> The digits can form an additive sequence: 1, 1, 2, 3, 5, 8. +> +> 1 + 1 = 2, 1 + 2 = 3, 2 + 3 = 5, 3 + 5 = 8 + +**Example 2:** + +> Input: "199100199" +> +> Output: true +> +> Explanation: +> +> The additive sequence is: 1, 99, 100, 199. +> +> 1 + 99 = 100, 99 + 100 = 199 + +**Constraints:** + +- `1 <= num.length <= 35` +- `num` consists only of digits. + +**Follow up:** How would you handle overflow for very large input integers? + +## 题目大意 + +**累加数** 是一个字符串,组成它的数字可以形成累加序列。 + +一个有效的 **累加序列** 必须**至少** 包含 3 个数。除了最开始的两个数以外,序列中的每个后续数字必须是它之前两个数字之和。 + +给你一个只包含数字 `'0'-'9'` 的字符串,编写一个算法来判断给定输入是否是 **累加数** 。如果是,返回 `true` ;否则,返回 +`false` 。 + +**说明:** 累加序列里的数,除数字 0 之外,**不会** 以 0 开头,所以不会出现 `1, 2, 03` 或者 `1, 02, 3` 的情况。 + +**示例 1:** + +> **输入:**"112358" +> +> **输出:** true +> +> **解释:** 累加序列为: 1, 1, 2, 3, 5, 8 。1 + 1 = 2, 1 + 2 = 3, 2 + 3 = 5, 3 + 5 = 8 + +**示例 2:** + +> **输入:**"199100199" +> +> **输出:** true +> +> **解释:** 累加序列为: 1, 99, 100, 199。1 + 99 = 100, 99 + 100 = 199 + +**提示:** + +- `1 <= num.length <= 35` +- `num` 仅由数字(`0 - 9`)组成 + +**进阶:** 你计划如何处理由过大的整数输入导致的溢出? + +## 解题思路 + +### 思路一:回溯法 + +1. 定义一个数组 `track`,存储当前选取的累加数序列。 +2. 从字符串的起始位置 `start` 开始递归: + - 终止条件:当字符串遍历完且累加数序列长度 ≥ 3 时,返回 `true`。 + - 枚举从 `start` 到 `num.length` 的所有子串: + 1. 如果子串有前导零且长度大于 1,则跳过。 + 2. 将子串转换为数字 `next`,判断是否满足累加数性质: + - 如果满足,将其加入 `track` 并递归。 + - 如果递归成功,则直接返回 `true`。 + - 否则,回溯,移除当前数字。 + - 剪枝优化:如果当前子串的值不等于前两个数字之和,直接跳过当前分割。 +3. 如果所有分割均不满足条件,返回 `false`。 + +#### 复杂度分析 + +- **时间复杂度**:`O(2^n)`,每个字符都有两种选择(加入当前数字或不加入)。 +- **空间复杂度**:`O(n)`,递归栈和存储路径的数组。 + +--- + +### 思路二:迭代法 + +1. 使用两层循环枚举前两个数字的分割位置,确定初始的两个累加数: + - 第一层循环确定第一个数字的长度。 + - 第二层循环确定第二个数字的长度。 +2. 从第三个数字开始,逐步验证剩余部分是否满足累加数性质。 +3. 验证过程: + - 初始化两个累加数 `first` 和 `second`。 + - 从剩余字符串中逐个匹配累加和: + - 如果匹配成功,则更新累加数,继续验证下一个数字。 + - 如果不匹配,立即终止当前分割。 +4. 如果某种分割方式成功匹配完整个字符串,则返回 `true`;否则,返回 `false`。 + +#### 复杂度分析 + +- **时间复杂度**:`O(2^n)`,两层循环枚举所有可能的分割点。 +- **空间复杂度**:`O(1)`,无需额外的递归栈或路径存储。 + +## 代码 + +::: code-tabs +@tab 回溯法 + +```javascript +/** + * @param {string} num + * @return {boolean} + */ +var isAdditiveNumber = function (num) { + let track = []; + + const backtrack = (start) => { + if (start === num.length && track.length >= 3) return true; + + for (let i = start; i < num.length; i++) { + if (num[start] === '0' && i > start) break; // 前导零 + const next = Number(num.slice(start, i + 1)); + + if ( + track.length >= 2 && + track[track.length - 1] + track[track.length - 2] !== next + ) { + continue; + } + + track.push(next); + if (backtrack(i + 1)) return true; + track.pop(); + } + return false; + }; + + return backtrack(0); +}; +``` + +@tab 迭代法 + +```javascript +/** + * @param {string} num + * @return {boolean} + */ +var isAdditiveNumber = function (num) { + const n = num.length; + + const isValid = (first, second, start) => { + while (start < n) { + const sum = first + second; + const sumStr = sum.toString(); + + // 如果剩余的字符串不以 sumStr 开头,直接返回 false + if (!num.startsWith(sumStr, start)) return false; + + // 移动到下一段 + start += sumStr.length; + + // 更新 first 和 second + [first, second] = [second, sum]; + } + return true; + }; + + for (let i = 1; i < n; i++) { + if (i > 1 && num[0] === '0') break; // 第一个数字不能有前导零 + const first = Number(num.slice(0, i)); + + for (let j = i + 1; j < n; j++) { + if (j > i + 1 && num[i] === '0') break; // 第二个数字不能有前导零 + const second = Number(num.slice(i, j)); + + // 检查从 j 开始的序列是否满足累加数性质 + if (isValid(first, second, j)) return true; + } + } + + return false; +}; +``` + +::: + +## 相关题目 + + +| 题号 | 标题 | 题解 | 标签 | 难度 | 力扣 | +| :------: | :------ | :------: | :------ | :------: | :------: | +| 842 | 将数组拆分成斐波那契序列 | | [`字符串`](/tag/string.md) [`回溯`](/tag/backtracking.md) | 🟠 | [🀄️](https://leetcode.cn/problems/split-array-into-fibonacci-sequence) [🔗](https://leetcode.com/problems/split-array-into-fibonacci-sequence) | \ No newline at end of file diff --git a/src/problem/0310.md b/src/problem/0310.md new file mode 100644 index 0000000000..15b6547fc7 --- /dev/null +++ b/src/problem/0310.md @@ -0,0 +1,192 @@ +--- +title: 310. 最小高度树 +description: LeetCode 310. 最小高度树题解,Minimum Height Trees,包含解题思路、复杂度分析以及完整的 JavaScript 代码实现。 +keywords: + - LeetCode + - 310. 最小高度树 + - 最小高度树 + - Minimum Height Trees + - 解题思路 + - 深度优先搜索 + - 广度优先搜索 + - 图 + - 拓扑排序 +--- + +# 310. 最小高度树 + +🟠 Medium  🔖  [`深度优先搜索`](/tag/depth-first-search.md) [`广度优先搜索`](/tag/breadth-first-search.md) [`图`](/tag/graph.md) [`拓扑排序`](/tag/topological-sort.md)  🔗 [`力扣`](https://leetcode.cn/problems/minimum-height-trees) [`LeetCode`](https://leetcode.com/problems/minimum-height-trees) + +## 题目 + +A tree is an undirected graph in which any two vertices are connected by +_exactly_ one path. In other words, any connected graph without simple cycles +is a tree. + +Given a tree of `n` nodes labelled from `0` to `n - 1`, and an array of `n - +1` `edges` where `edges[i] = [ai, bi]` indicates that there is an undirected +edge between the two nodes `ai` and `bi` in the tree, you can choose any node +of the tree as the root. When you select a node `x` as the root, the result +tree has height `h`. Among all possible rooted trees, those with minimum +height (i.e. `min(h)`) are called **minimum height trees** (MHTs). + +Return _a list of all**MHTs '** root labels_. You can return the answer in +**any order**. + +The **height** of a rooted tree is the number of edges on the longest downward +path between the root and a leaf. + +**Example 1:** + +![](https://assets.leetcode.com/uploads/2020/09/01/e1.jpg) + +> Input: n = 4, edges = [[1,0],[1,2],[1,3]] +> +> Output: [1] +> +> Explanation: As shown, the height of the tree is 1 when the root is the node with label 1 which is the only MHT. + +**Example 2:** + +![](https://assets.leetcode.com/uploads/2020/09/01/e2.jpg) + +> Input: n = 6, edges = [[3,0],[3,1],[3,2],[3,4],[5,4]] +> +> Output: [3,4] + +**Constraints:** + +- `1 <= n <= 2 * 10^4` +- `edges.length == n - 1` +- `0 <= ai, bi < n` +- `ai != bi` +- All the pairs `(ai, bi)` are distinct. +- The given input is **guaranteed** to be a tree and there will be **no repeated** edges. + +## 题目大意 + +树是一个无向图,其中任何两个顶点只通过一条路径连接。 换句话说,任何一个没有简单环路的连通图都是一棵树。 + +给你一棵包含 `n` 个节点的树,标记为 `0` 到 `n - 1` 。给定数字 `n` 和一个有 `n - 1` 条无向边的 `edges` +列表(每一个边都是一对标签),其中 `edges[i] = [ai, bi]` 表示树中节点 `ai` 和 `bi` 之间存在一条无向边。 + +可选择树中任何一个节点作为根。当选择节点 `x` 作为根节点时,设结果树的高度为 `h` 。在所有可能的树中,具有最小高度的树(即,`min(h)`)被称为 +**最小高度树** 。 + +请你找到所有的 **最小高度树** 并按 **任意顺序** 返回它们的根节点标签列表。 + +树的 **高度** 是指根节点和叶子节点之间最长向下路径上边的数量。 + +**示例 1:** + +![](https://assets.leetcode.com/uploads/2020/09/01/e1.jpg) + +> **输入:** n = 4, edges = [[1,0],[1,2],[1,3]] +> +> **输出:**[1] +> +> **解释:** 如图所示,当根是标签为 1 的节点时,树的高度是 1 ,这是唯一的最小高度树。 + +**示例 2:** + +![](https://assets.leetcode.com/uploads/2020/09/01/e2.jpg) + +> **输入:** n = 6, edges = [[3,0],[3,1],[3,2],[3,4],[5,4]] +> +> **输出:**[3,4] + +**提示:** + +- `1 <= n <= 2 * 10^4` +- `edges.length == n - 1` +- `0 <= ai, bi < n` +- `ai != bi` +- 所有 `(ai, bi)` 互不相同 +- 给定的输入 **保证** 是一棵树,并且 **不会有重复的边** + +## 解题思路 + +1. **树的直径特性**: + + - 最小高度树的根节点一定是树的直径的中点。 + - 树的直径是指树中任意两个节点之间最长路径的长度。树的直径的中点(1 个或 2 个)就是最小高度树的根节点。 + - 可以通过逐层移除叶节点的方法,找到树的直径的中点。 + +2. **构造图**: + + - 用邻接表表示树的结构。 + +3. **找到所有叶节点**: + + - 叶节点是指度为 `1` 的节点。 + +4. **逐层移除叶节点**: + + - 每次将当前所有叶节点移除,同时更新与这些叶节点相连的节点的度数。 + - 如果某个节点的度数变为 `1`,它成为新的叶节点。 + +5. **终止条件**: + - 当剩余节点数小于或等于 `2` 时,停止移除。这些剩余的节点就是树的直径的中点,也就是最小高度树的根节点。 + +#### 复杂度分析 + +- **时间复杂度**:`O(n)`,构建图的时间复杂度为 `O(n)`,逐层移除叶节点的复杂度也为 `O(n)`,总体时间复杂度为 `O(n)`。 +- **空间复杂度**:`O(n)`,邻接表的空间复杂度为 `O(n)`,队列的空间复杂度为 `O(n)`,总体为 `O(n)`。 + +## 代码 + +```javascript +/** + * @param {number} n + * @param {number[][]} edges + * @return {number[]} + */ +var findMinHeightTrees = function (n, edges) { + if (n === 1) return [0]; // 特殊情况:只有一个节点 + if (n === 2) return [0, 1]; // 特殊情况:两个节点 + + // 构建邻接表 + const graph = new Array(n).fill(0).map(() => []); + for (const [u, v] of edges) { + graph[u].push(v); + graph[v].push(u); + } + + // 找到所有叶节点(度为 1 的节点) + const leaves = []; + const degree = new Array(n).fill(0); + for (let i = 0; i < n; i++) { + degree[i] = graph[i].length; + if (degree[i] === 1) leaves.push(i); + } + + // 逐层移除叶节点 + let remainingNodes = n; + while (remainingNodes > 2) { + const size = leaves.length; + remainingNodes -= size; + + for (let i = 0; i < size; i++) { + const leaf = leaves.shift(); + for (const neighbor of graph[leaf]) { + degree[neighbor]--; + if (degree[neighbor] === 1) leaves.push(neighbor); + } + } + } + + // 剩余节点即为结果 + return leaves; +}; +``` + +## 相关题目 + + +| 题号 | 标题 | 题解 | 标签 | 难度 | 力扣 | +| :------: | :------ | :------: | :------ | :------: | :------: | +| 207 | 课程表 | [[✓]](/problem/0207.md) | [`深度优先搜索`](/tag/depth-first-search.md) [`广度优先搜索`](/tag/breadth-first-search.md) [`图`](/tag/graph.md) `1+` | 🟠 | [🀄️](https://leetcode.cn/problems/course-schedule) [🔗](https://leetcode.com/problems/course-schedule) | +| 210 | 课程表 II | [[✓]](/problem/0210.md) | [`深度优先搜索`](/tag/depth-first-search.md) [`广度优先搜索`](/tag/breadth-first-search.md) [`图`](/tag/graph.md) `1+` | 🟠 | [🀄️](https://leetcode.cn/problems/course-schedule-ii) [🔗](https://leetcode.com/problems/course-schedule-ii) | +| 2603 | 收集树中金币 | | [`树`](/tag/tree.md) [`图`](/tag/graph.md) [`拓扑排序`](/tag/topological-sort.md) `1+` | 🔴 | [🀄️](https://leetcode.cn/problems/collect-coins-in-a-tree) [🔗](https://leetcode.com/problems/collect-coins-in-a-tree) | +| 3067 | 在带权树网络中统计可连接服务器对数目 | | [`树`](/tag/tree.md) [`深度优先搜索`](/tag/depth-first-search.md) [`数组`](/tag/array.md) | 🟠 | [🀄️](https://leetcode.cn/problems/count-pairs-of-connectable-servers-in-a-weighted-tree-network) [🔗](https://leetcode.com/problems/count-pairs-of-connectable-servers-in-a-weighted-tree-network) | +| 3203 | 合并两棵树后的最小直径 | [[✓]](/problem/3203.md) | [`树`](/tag/tree.md) [`深度优先搜索`](/tag/depth-first-search.md) [`广度优先搜索`](/tag/breadth-first-search.md) `1+` | 🔴 | [🀄️](https://leetcode.cn/problems/find-minimum-diameter-after-merging-two-trees) [🔗](https://leetcode.com/problems/find-minimum-diameter-after-merging-two-trees) | \ No newline at end of file diff --git a/src/problem/0313.md b/src/problem/0313.md new file mode 100644 index 0000000000..bc230356de --- /dev/null +++ b/src/problem/0313.md @@ -0,0 +1,158 @@ +--- +title: 313. 超级丑数 +description: LeetCode 313. 超级丑数题解,Super Ugly Number,包含解题思路、复杂度分析以及完整的 JavaScript 代码实现。 +keywords: + - LeetCode + - 313. 超级丑数 + - 超级丑数 + - Super Ugly Number + - 解题思路 + - 数组 + - 数学 + - 动态规划 +--- + +# 313. 超级丑数 + +🟠 Medium  🔖  [`数组`](/tag/array.md) [`数学`](/tag/math.md) [`动态规划`](/tag/dynamic-programming.md)  🔗 [`力扣`](https://leetcode.cn/problems/super-ugly-number) [`LeetCode`](https://leetcode.com/problems/super-ugly-number) + +## 题目 + +A **super ugly number** is a positive integer whose prime factors are in the +array `primes`. + +Given an integer `n` and an array of integers `primes`, return _the_ `nth` +_**super ugly number**_. + +The `nth` **super ugly number** is **guaranteed** to fit in a **32-bit** +signed integer. + +**Example 1:** + +> Input: n = 12, primes = [2,7,13,19] +> +> Output: 32 +> +> Explanation: [1,2,4,7,8,13,14,16,19,26,28,32] is the sequence of the first 12 super ugly numbers given primes = [2,7,13,19]. + +**Example 2:** + +> Input: n = 1, primes = [2,3,5] +> +> Output: 1 +> +> Explanation: 1 has no prime factors, therefore all of its prime factors are in the array primes = [2,3,5]. + +**Constraints:** + +- `1 <= n <= 10^5` +- `1 <= primes.length <= 100` +- `2 <= primes[i] <= 1000` +- `primes[i]` is **guaranteed** to be a prime number. +- All the values of `primes` are **unique** and sorted in **ascending order**. + +## 题目大意 + +**超级丑数** 是一个正整数,并满足其所有质因数都出现在质数数组 `primes` 中。 + +给你一个整数 `n` 和一个整数数组 `primes` ,返回第 `n` 个 **超级丑数** 。 + +题目数据保证第 `n` 个 **超级丑数** 在 **32-bit** 带符号整数范围内。 + +**示例 1:** + +> **输入:** n = 12, primes = [2,7,13,19] +> +> **输出:** 32 +> +> **解释:** 给定长度为 4 的质数数组 primes = [2,7,13,19],前 12 个超级丑数序列为:[1,2,4,7,8,13,14,16,19,26,28,32] 。 + +**示例 2:** + +> **输入:** n = 1, primes = [2,3,5] +> +> **输出:** 1 +> +> **解释:** 1 不含质因数,因此它的所有质因数都在质数数组 primes = [2,3,5] 中。 + +**提示:** + +- `1 <= n <= 10^5` +- `1 <= primes.length <= 100` +- `2 <= primes[i] <= 1000` +- 题目数据**保证** `primes[i]` 是一个质数 +- `primes` 中的所有值都 **互不相同** ,且按 **递增顺序** 排列 + +## 解题思路 + +这道题是对 **丑数问题** 的拓展,利用动态规划和多指针法来生成超级丑数。核心思想是不断计算当前的最小丑数并扩展出新的丑数。 + +1. **定义状态**: + + - `dp[i]` 表示第 `i+1` 个超级丑数。 + - 初始化 `dp[0] = 1`。 + +2. **多指针数组**: + + - 使用一个数组 `idx`,`idx[j]` 表示质因子 `primes[j]` 对应的指针在 `dp` 中的索引位置。 + - 初始时 `idx = [0, 0, ..., 0]`。 + +3. **当前丑数的生成**: + + - 对每个质因子 `primes[j]`,计算其生成的丑数: + `uglyNums[j] = dp[idx[j]] * primes[j]`。 + +4. **选取最小值**: + + - 当前的超级丑数是 `ugly = Math.min(...uglyNums)`。 + +5. **更新指针**: + + - 如果某个 `uglyNums[j]` 等于当前的 `ugly`,则增加 `idx[j]`,表示 `primes[j]` 的指针向右移动。 + +6. **重复计算**: + - 不断重复上述过程,直到找到第 `n` 个超级丑数。 + +#### 复杂度分析 + +- **时间复杂度**:`O(n * m)`,动态规划计算 `n` 个超级丑数,每次需要从 `m` 个质因子中找到最小值。 +- **空间复杂度**:`O(n + m)`,需要存储动态规划数组 `dp` 和辅助数组 `idx`、`uglyNums`。 + +## 代码 + +```javascript +/** + * @param {number} n + * @param {number[]} primes + * @return {number} + */ +var nthSuperUglyNumber = function (n, primes) { + const m = primes.length; + const dp = [1]; // 动态规划数组 + const idx = new Array(m).fill(0); // 每个质因子的指针 + const uglyNums = new Array(m).fill(1); // 每个质因子当前对应的丑数 + + for (let i = 1; i < n; i++) { + // 找到当前的最小丑数 + const ugly = Math.min(...uglyNums); + dp.push(ugly); + + // 更新指针和对应丑数 + for (let j = 0; j < m; j++) { + if (uglyNums[j] === ugly) { + uglyNums[j] = dp[idx[j]] * primes[j]; + idx[j]++; + } + } + } + + return dp[n - 1]; +}; +``` + +## 相关题目 + + +| 题号 | 标题 | 题解 | 标签 | 难度 | 力扣 | +| :------: | :------ | :------: | :------ | :------: | :------: | +| 264 | 丑数 II | [[✓]](/problem/0264.md) | [`哈希表`](/tag/hash-table.md) [`数学`](/tag/math.md) [`动态规划`](/tag/dynamic-programming.md) `1+` | 🟠 | [🀄️](https://leetcode.cn/problems/ugly-number-ii) [🔗](https://leetcode.com/problems/ugly-number-ii) | \ No newline at end of file diff --git a/src/problem/0318.md b/src/problem/0318.md new file mode 100644 index 0000000000..c4535d1976 --- /dev/null +++ b/src/problem/0318.md @@ -0,0 +1,145 @@ +--- +title: 318. 最大单词长度乘积 +description: LeetCode 318. 最大单词长度乘积题解,Maximum Product of Word Lengths,包含解题思路、复杂度分析以及完整的 JavaScript 代码实现。 +keywords: + - LeetCode + - 318. 最大单词长度乘积 + - 最大单词长度乘积 + - Maximum Product of Word Lengths + - 解题思路 + - 位运算 + - 数组 + - 字符串 +--- + +# 318. 最大单词长度乘积 + +🟠 Medium  🔖  [`位运算`](/tag/bit-manipulation.md) [`数组`](/tag/array.md) [`字符串`](/tag/string.md)  🔗 [`力扣`](https://leetcode.cn/problems/maximum-product-of-word-lengths) [`LeetCode`](https://leetcode.com/problems/maximum-product-of-word-lengths) + +## 题目 + +Given a string array `words`, return _the maximum value of_ `length(word[i]) * +length(word[j])` _where the two words do not share common letters_. If no such +two words exist, return `0`. + +**Example 1:** + +> Input: words = ["abcw","baz","foo","bar","xtfn","abcdef"] +> +> Output: 16 +> +> Explanation: The two words can be "abcw", "xtfn". + +**Example 2:** + +> Input: words = ["a","ab","abc","d","cd","bcd","abcd"] +> +> Output: 4 +> +> Explanation: The two words can be "ab", "cd". + +**Example 3:** + +> Input: words = ["a","aa","aaa","aaaa"] +> +> Output: 0 +> +> Explanation: No such pair of words. + +**Constraints:** + +- `2 <= words.length <= 1000` +- `1 <= words[i].length <= 1000` +- `words[i]` consists only of lowercase English letters. + +## 题目大意 + +给你一个字符串数组 `words` ,找出并返回 `length(words[i]) * length(words[j])` +的最大值,并且这两个单词不含有公共字母。如果不存在这样的两个单词,返回 `0` 。 + +**示例 1:** + +> **输入:** words = ["abcw","baz","foo","bar","xtfn","abcdef"] +> +> **输出:**16 +> +> **解释**:**这两个单词为** "abcw", "xtfn"。 + +**示例 2:** + +> **输入:** words = ["a","ab","abc","d","cd","bcd","abcd"] +> +> **输出:**4 +> +> **解释**: 这两个单词为 "ab", "cd"。 + +**示例 3:** + +> **输入:** words = ["a","aa","aaa","aaaa"] +> +> **输出:**0 +> +> **解释**:不存在这样的两个单词。 + +**提示:** + +- `2 <= words.length <= 1000` +- `1 <= words[i].length <= 1000` +- `words[i]` 仅包含小写字母 + +## 解题思路 + +1. **构造位掩码**: + + - 对每个单词,遍历其字符,根据字符的 ASCII 值计算相应位的位置,将该位置的二进制位设为 1。 + +2. **比较两两单词**: + + - 用两层循环比较所有单词对。 + - 如果两个单词的位掩码按位与的结果为 0,则计算它们长度的乘积,并更新最大值。 + +3. **返回结果**: + - 最后返回最大乘积。 + +#### 复杂度分析 + +- **时间复杂度**:`O(n * L + n^2)` + + - 构造位掩码:对每个单词遍历其字符,复杂度为 `O(n * L)`,其中 `n` 是单词数,`L` 是单词的平均长度。 + - 比较两两单词:两层循环,复杂度为 `O(n^2)`。 + - 整体复杂度为 `O(n * L + n^2)`。 + +- **空间复杂度**:`O(n)`,存储每个单词的位掩码。 + +## 代码 + +```javascript +/** + * @param {string[]} words + * @return {number} + */ +var maxProduct = function (words) { + // 构造每个单词的位掩码 + const values = words.map((word) => { + let mask = 0; + for (let char of word) { + mask |= 1 << (char.charCodeAt() - 97); // 将对应字母位置的二进制位设为 1 + } + return mask; + }); + + let maxProduct = 0; + + // 比较两两单词 + for (let i = 0; i < words.length; i++) { + for (let j = i + 1; j < words.length; j++) { + // 如果没有公共字母,计算长度乘积 + if ((values[i] & values[j]) === 0) { + maxProduct = Math.max(maxProduct, words[i].length * words[j].length); + } + } + } + + return maxProduct; +}; +``` diff --git a/src/problem/0319.md b/src/problem/0319.md new file mode 100644 index 0000000000..be4e548ee7 --- /dev/null +++ b/src/problem/0319.md @@ -0,0 +1,153 @@ +--- +title: 319. 灯泡开关 +description: LeetCode 319. 灯泡开关题解,Bulb Switcher,包含解题思路、复杂度分析以及完整的 JavaScript 代码实现。 +keywords: + - LeetCode + - 319. 灯泡开关 + - 灯泡开关 + - Bulb Switcher + - 解题思路 + - 脑筋急转弯 + - 数学 +--- + +# 319. 灯泡开关 + +🟠 Medium  🔖  [`脑筋急转弯`](/tag/brainteaser.md) [`数学`](/tag/math.md)  🔗 [`力扣`](https://leetcode.cn/problems/bulb-switcher) [`LeetCode`](https://leetcode.com/problems/bulb-switcher) + +## 题目 + +There are `n` bulbs that are initially off. You first turn on all the bulbs, +then you turn off every second bulb. + +On the third round, you toggle every third bulb (turning on if it's off or +turning off if it's on). For the `ith` round, you toggle every `i` bulb. For +the `nth` round, you only toggle the last bulb. + +Return _the number of bulbs that are on after`n` rounds_. + +**Example 1:** + +![](https://assets.leetcode.com/uploads/2020/11/05/bulb.jpg) + +> Input: n = 3 +> +> Output: 1 +> +> Explanation: At first, the three bulbs are [off, off, off]. +> +> After the first round, the three bulbs are [on, on, on]. +> +> After the second round, the three bulbs are [on, off, on]. +> +> After the third round, the three bulbs are [on, off, off]. +> +> So you should return 1 because there is only one bulb is on. + +**Example 2:** + +> Input: n = 0 +> +> Output: 0 + +**Example 3:** + +> Input: n = 1 +> +> Output: 1 + +**Constraints:** + +- `0 <= n <= 10^9` + +## 题目大意 + +初始时有 `n` 个灯泡处于关闭状态。第一轮,你将会打开所有灯泡。接下来的第二轮,你将会每两个灯泡关闭第二个。 + +第三轮,你每三个灯泡就切换第三个灯泡的开关(即,打开变关闭,关闭变打开)。第 `i` 轮,你每 `i` 个灯泡就切换第 `i` 个灯泡的开关。直到第 `n` +轮,你只需要切换最后一个灯泡的开关。 + +找出并返回 `n` 轮后有多少个亮着的灯泡。 + +**示例 1:** + +![](https://assets.leetcode.com/uploads/2020/11/05/bulb.jpg) + +> **输入:** n = 3 +> +> **输出:** 1 +> +> **解释:** +> +> 初始时, 灯泡状态 **[关闭, 关闭, 关闭]**. +> +> 第一轮后, 灯泡状态 **[开启, 开启, 开启]**. +> +> 第二轮后, 灯泡状态 **[开启, 关闭, 开启]**. +> +> 第三轮后, 灯泡状态 **[开启, 关闭, 关闭]**. +> +> 你应该返回 1,因为只有一个灯泡还亮着。 + +**示例 2:** + +> **输入:** n = 0 +> +> **输出:** 0 + +**示例 3:** + +> **输入:** n = 1 +> +> **输出:** 1 + +**提示:** + +- `0 <= n <= 10^9` + +## 解题思路 + +**1. 状态变化规律** + +- 灯泡是否亮着,取决于它被切换的次数: + - 如果一个灯泡的编号有奇数个因数,则它是亮的。 + - 如果一个灯泡的编号有偶数个因数,则它是灭的。 + +**2. 数学分析** + +- 一个数的因数通常是成对出现的,例如: + - 6 的因数有 {1, 6}, {2, 3},因数成对。 +- 只有 **完全平方数** 才有奇数个因数,例如: + - 9 的因数有 {1, 9}, {3},因数不成对。 + +**3. 问题转化** + +- 问题变为:`n` 的范围内有多少个完全平方数。 + - 这等价于求 `floor(sqrt(n))`,即平方数的个数。 + +#### 复杂度分析 + +- **时间复杂度**:`O(1)`,计算平方根的时间复杂度为 `O(1)`。 +- **空间复杂度**:`O(1)`,只需常数额外空间。 + +## 代码 + +```javascript +/** + * @param {number} n + * @return {number} + */ +var bulbSwitch = function (n) { + return Math.floor(Math.sqrt(n)); +}; +``` + +## 相关题目 + + +| 题号 | 标题 | 题解 | 标签 | 难度 | 力扣 | +| :------: | :------ | :------: | :------ | :------: | :------: | +| 672 | 灯泡开关 Ⅱ | | [`位运算`](/tag/bit-manipulation.md) [`深度优先搜索`](/tag/depth-first-search.md) [`广度优先搜索`](/tag/breadth-first-search.md) `1+` | 🟠 | [🀄️](https://leetcode.cn/problems/bulb-switcher-ii) [🔗](https://leetcode.com/problems/bulb-switcher-ii) | +| 995 | K 连续位的最小翻转次数 | | [`位运算`](/tag/bit-manipulation.md) [`队列`](/tag/queue.md) [`数组`](/tag/array.md) `2+` | 🔴 | [🀄️](https://leetcode.cn/problems/minimum-number-of-k-consecutive-bit-flips) [🔗](https://leetcode.com/problems/minimum-number-of-k-consecutive-bit-flips) | +| 1375 | 二进制字符串前缀一致的次数 | | [`数组`](/tag/array.md) | 🟠 | [🀄️](https://leetcode.cn/problems/number-of-times-binary-string-is-prefix-aligned) [🔗](https://leetcode.com/problems/number-of-times-binary-string-is-prefix-aligned) | +| 2485 | 找出中枢整数 | | [`数学`](/tag/math.md) [`前缀和`](/tag/prefix-sum.md) | 🟢 | [🀄️](https://leetcode.cn/problems/find-the-pivot-integer) [🔗](https://leetcode.com/problems/find-the-pivot-integer) | \ No newline at end of file diff --git a/src/problem/0331.md b/src/problem/0331.md new file mode 100644 index 0000000000..3f23e305e7 --- /dev/null +++ b/src/problem/0331.md @@ -0,0 +1,150 @@ +--- +title: 331. 验证二叉树的前序序列化 +description: LeetCode 331. 验证二叉树的前序序列化题解,Verify Preorder Serialization of a Binary Tree,包含解题思路、复杂度分析以及完整的 JavaScript 代码实现。 +keywords: + - LeetCode + - 331. 验证二叉树的前序序列化 + - 验证二叉树的前序序列化 + - Verify Preorder Serialization of a Binary Tree + - 解题思路 + - 栈 + - 树 + - 字符串 + - 二叉树 +--- + +# 331. 验证二叉树的前序序列化 + +🟠 Medium  🔖  [`栈`](/tag/stack.md) [`树`](/tag/tree.md) [`字符串`](/tag/string.md) [`二叉树`](/tag/binary-tree.md)  🔗 [`力扣`](https://leetcode.cn/problems/verify-preorder-serialization-of-a-binary-tree) [`LeetCode`](https://leetcode.com/problems/verify-preorder-serialization-of-a-binary-tree) + +## 题目 + +One way to serialize a binary tree is to use **preorder traversal**. When we +encounter a non-null node, we record the node's value. If it is a null node, +we record using a sentinel value such as `'#'`. + +![](https://assets.leetcode.com/uploads/2021/03/12/pre-tree.jpg) + +For example, the above binary tree can be serialized to the string +`"9,3,4,#,#,1,#,#,2,#,6,#,#"`, where `'#'` represents a null node. + +Given a string of comma-separated values `preorder`, return `true` if it is a +correct preorder traversal serialization of a binary tree. + +It is **guaranteed** that each comma-separated value in the string must be +either an integer or a character `'#'` representing null pointer. + +You may assume that the input format is always valid. + +- For example, it could never contain two consecutive commas, such as `"1,,3"`. + +**Note: **You are not allowed to reconstruct the tree. + +**Example 1:** + +> Input: preorder = "9,3,4,#,#,1,#,#,2,#,6,#,#" +> +> Output: true + +**Example 2:** + +> Input: preorder = "1,#" +> +> Output: false + +**Example 3:** + +> Input: preorder = "9,#,#,1" +> +> Output: false + +**Constraints:** + +- `1 <= preorder.length <= 10^4` +- `preorder` consist of integers in the range `[0, 100]` and `'#'` separated by commas `','`. + +## 题目大意 + +序列化二叉树的一种方法是使用 **前序遍历** 。当我们遇到一个非空节点时,我们可以记录下这个节点的值。如果它是一个空节点,我们可以使用一个标记值记录,例如 +`#`。 + +![](https://assets.leetcode.com/uploads/2021/03/12/pre-tree.jpg) + +例如,上面的二叉树可以被序列化为字符串 `"9,3,4,#,#,1,#,#,2,#,6,#,#"`,其中 `#` 代表一个空节点。 + +给定一串以逗号分隔的序列,验证它是否是正确的二叉树的前序序列化。编写一个在不重构树的条件下的可行算法。 + +**保证** 每个以逗号分隔的字符或为一个整数或为一个表示 `null` 指针的 `'#'` 。 + +你可以认为输入格式总是有效的 + +- 例如它永远不会包含两个连续的逗号,比如 `"1,,3"` 。 + +**注意:** 不允许重建树。 + +**示例 1:** + +> **输入:** preorder = "9,3,4,#,#,1,#,#,2,#,6,#,#" +> +> **输出:**true + +**示例 2:** + +> **输入:** preorder = "1,#" +> +> **输出:**false + +**示例 3:** + +> **输入:** preorder = "9,#,#,1" +> +> **输出:**false + +**提示:** + +- `1 <= preorder.length <= 10^4` +- `preorder` 由以逗号 `“,”` 分隔的 `[0,100]` 范围内的整数和 `“#”` 组成 + +## 解题思路 + +1. 使用一个指针 `i` 遍历 `preorder`,初始指向根节点。 +2. DFS 验证序列化,定义递归函数 `dfs()` 来验证子树是否合法: + + - 如果当前节点是 `#`,直接返回 `true`(空节点合法)。 + - 如果是非空节点,则递归检查左子树和右子树。 + +3. 最终需要检查: + + - `dfs()` 是否成功完成。 + - 遍历的节点数是否恰好覆盖了 `preorder`。 + +4. 非法情况: + + - 空节点数量不足,遍历时 `i` 超出数组长度。 + - 子树验证完成后,仍有未使用的节点(即多余的节点)。 + +#### 复杂度分析 + +- **时间复杂度**:`O(n)`,其中 `n` 是 `preorder` 的长度,每个节点最多访问一次。 +- **空间复杂度**:`O(h)`,其中 `h` 是树的高度,递归调用栈的空间复杂度为 `O(h)`,最差情况下为 `O(n)`。 + +## 代码 + +```javascript +/** + * @param {string} preorder + * @return {boolean} + */ +var isValidSerialization = function (preorder) { + const nodes = preorder.split(','); + let i = 0; + + const dfs = () => { + if (i >= nodes.length) return false; // 越界情况 + if (nodes[i++] === '#') return true; // 空节点,合法 + return dfs() && dfs(); // 递归验证左、右子树 + }; + + return dfs() && i === nodes.length; // 检查是否完整遍历 +}; +``` diff --git a/src/problem/0337.md b/src/problem/0337.md new file mode 100644 index 0000000000..60a22a73c5 --- /dev/null +++ b/src/problem/0337.md @@ -0,0 +1,153 @@ +--- +title: 337. 打家劫舍 III +description: LeetCode 337. 打家劫舍 III题解,House Robber III,包含解题思路、复杂度分析以及完整的 JavaScript 代码实现。 +keywords: + - LeetCode + - 337. 打家劫舍 III + - 打家劫舍 III + - House Robber III + - 解题思路 + - 树 + - 深度优先搜索 + - 动态规划 + - 二叉树 +--- + +# 337. 打家劫舍 III + +🟠 Medium  🔖  [`树`](/tag/tree.md) [`深度优先搜索`](/tag/depth-first-search.md) [`动态规划`](/tag/dynamic-programming.md) [`二叉树`](/tag/binary-tree.md)  🔗 [`力扣`](https://leetcode.cn/problems/house-robber-iii) [`LeetCode`](https://leetcode.com/problems/house-robber-iii) + +## 题目 + +The thief has found himself a new place for his thievery again. There is only +one entrance to this area, called `root`. + +Besides the `root`, each house has one and only one parent house. After a +tour, the smart thief realized that all houses in this place form a binary +tree. It will automatically contact the police if **two directly-linked houses +were broken into on the same night**. + +Given the `root` of the binary tree, return _the maximum amount of money the +thief can rob**without alerting the police**_. + +**Example 1:** + +![](https://assets.leetcode.com/uploads/2021/03/10/rob1-tree.jpg) + +> Input: root = [3,2,3,null,3,null,1] +> +> Output: 7 +> +> Explanation: Maximum amount of money the thief can rob = 3 + 3 + 1 = 7. + +**Example 2:** + +![](https://assets.leetcode.com/uploads/2021/03/10/rob2-tree.jpg) + +> Input: root = [3,4,5,1,3,null,1] +> +> Output: 9 +> +> Explanation: Maximum amount of money the thief can rob = 4 + 5 = 9. + +**Constraints:** + +- The number of nodes in the tree is in the range `[1, 104]`. +- `0 <= Node.val <= 10^4` + +## 题目大意 + +小偷又发现了一个新的可行窃的地区。这个地区只有一个入口,我们称之为 `root` 。 + +除了 `root` 之外,每栋房子有且只有一个“父“房子与之相连。一番侦察之后,聪明的小偷意识到“这个地方的所有房屋的排列类似于一棵二叉树”。 如果 +**两个直接相连的房子在同一天晚上被打劫** ,房屋将自动报警。 + +给定二叉树的 `root` 。返回 _**在不触动警报的情况下** ,小偷能够盗取的最高金额_ 。 + +**示例 1:** + +![](https://assets.leetcode.com/uploads/2021/03/10/rob1-tree.jpg) + +> **输入:** root = [3,2,3,null,3,null,1] +> +> **输出:** 7 +> +> **解释:** 小偷一晚能够盗取的最高金额 3 + 3 + 1 = 7 + +**示例 2:** + +![](https://assets.leetcode.com/uploads/2021/03/10/rob2-tree.jpg) + +> **输入:** root = [3,4,5,1,3,null,1] +> +> **输出:** 9 +> +> **解释:** 小偷一晚能够盗取的最高金额 4 + 5 = 9 + +**提示:** + +- 树的节点数在 `[1, 104]` 范围内 +- `0 <= Node.val <= 10^4` + +## 解题思路 + +1. **问题分解** + + - 对于每个节点,有两种选择: + + - **偷取该节点**:那么它的两个子节点就不能被偷取。 + - **不偷取该节点**:可以选择偷取子节点。 + + - 我们使用一个数组 `[notRob, rob]` 表示两种状态: + - `notRob`: 不偷取当前节点的最大收益。 + - `rob`: 偷取当前节点的最大收益。 + +2. **递归状态转移** + + - **叶子节点的情况**: + - 如果当前节点为空,则 `[notRob, rob] = [0, 0]`。 + - **状态转移方程**: + - `notRob = max(left[0], left[1]) + max(right[0], right[1])` + - 当前节点不偷取,可以从左右子节点任意状态中选择最大值。 + - `rob = root.val + left[0] + right[0]` + - 当前节点偷取,只能加上左右子节点不偷取时的收益。 + +3. **最终结果** + - 对整棵树的根节点,取 `max(notRob, rob)`。 + +#### 复杂度分析 + +- **时间复杂度**:`O(n)`,其中 `n` 是树中节点的数量,每个节点访问一次。 +- **空间复杂度**:`O(h)`,其中 `h` 是树的高度,递归调用栈的空间复杂度为 `O(h)`,最差情况下为 `O(n)`(完全不平衡树)。 + +## 代码 + +```javascript +/** + * @param {TreeNode} root + * @return {number} + */ +var rob = function (root) { + const helper = (root) => { + if (root == null) return [0, 0]; + + const left = helper(root.left); + const right = helper(root.right); + + const notRob = Math.max(left[0], left[1]) + Math.max(right[0], right[1]); + const rob = root.val + left[0] + right[0]; + + return [notRob, rob]; + }; + + return Math.max(...helper(root)); +}; +``` + +## 相关题目 + + +| 题号 | 标题 | 题解 | 标签 | 难度 | 力扣 | +| :------: | :------ | :------: | :------ | :------: | :------: | +| 198 | 打家劫舍 | [[✓]](/problem/0198.md) | [`数组`](/tag/array.md) [`动态规划`](/tag/dynamic-programming.md) | 🟠 | [🀄️](https://leetcode.cn/problems/house-robber) [🔗](https://leetcode.com/problems/house-robber) | +| 213 | 打家劫舍 II | [[✓]](/problem/0213.md) | [`数组`](/tag/array.md) [`动态规划`](/tag/dynamic-programming.md) | 🟠 | [🀄️](https://leetcode.cn/problems/house-robber-ii) [🔗](https://leetcode.com/problems/house-robber-ii) | \ No newline at end of file diff --git a/src/problem/0341.md b/src/problem/0341.md new file mode 100644 index 0000000000..c0de5a2e6e --- /dev/null +++ b/src/problem/0341.md @@ -0,0 +1,184 @@ +--- +title: 341. 扁平化嵌套列表迭代器 +description: LeetCode 341. 扁平化嵌套列表迭代器题解,Flatten Nested List Iterator,包含解题思路、复杂度分析以及完整的 JavaScript 代码实现。 +keywords: + - LeetCode + - 341. 扁平化嵌套列表迭代器 + - 扁平化嵌套列表迭代器 + - Flatten Nested List Iterator + - 解题思路 + - 栈 + - 树 + - 深度优先搜索 + - 设计 + - 队列 + - 迭代器 +--- + +# 341. 扁平化嵌套列表迭代器 + +🟠 Medium  🔖  [`栈`](/tag/stack.md) [`树`](/tag/tree.md) [`深度优先搜索`](/tag/depth-first-search.md) [`设计`](/tag/design.md) [`队列`](/tag/queue.md) [`迭代器`](/tag/iterator.md)  🔗 [`力扣`](https://leetcode.cn/problems/flatten-nested-list-iterator) [`LeetCode`](https://leetcode.com/problems/flatten-nested-list-iterator) + +## 题目 + +You are given a nested list of integers `nestedList`. Each element is either +an integer or a list whose elements may also be integers or other lists. +Implement an iterator to flatten it. + +Implement the `NestedIterator` class: + +- `NestedIterator(List nestedList)` Initializes the iterator with the nested list `nestedList`. +- `int next()` Returns the next integer in the nested list. +- `boolean hasNext()` Returns `true` if there are still some integers in the nested list and `false` otherwise. + +Your code will be tested with the following pseudocode: + +> ```js +> initialize iterator with nestedList +> res = [] +> while iterator.hasNext() +> append iterator.next() to the end of res +> return res +> ``` + +If `res` matches the expected flattened list, then your code will be judged as +correct. + +**Example 1:** + +> Input: nestedList = [[1,1],2,[1,1]] +> +> Output: [1,1,2,1,1] +> +> Explanation: By calling next repeatedly until hasNext returns false, the order of elements returned by next should be: [1,1,2,1,1]. + +**Example 2:** + +> Input: nestedList = [1,[4,[6]]] +> +> Output: [1,4,6] +> +> Explanation: By calling next repeatedly until hasNext returns false, the order of elements returned by next should be: [1,4,6]. + +**Constraints:** + +- `1 <= nestedList.length <= 500` +- The values of the integers in the nested list is in the range `[-10^6, 10^6]`. + +## 题目大意 + +给你一个嵌套的整数列表 `nestedList` +。每个元素要么是一个整数,要么是一个列表;该列表的元素也可能是整数或者是其他列表。请你实现一个迭代器将其扁平化,使之能够遍历这个列表中的所有整数。 + +实现扁平迭代器类 `NestedIterator` : + +- `NestedIterator(List nestedList)` 用嵌套列表 `nestedList` 初始化迭代器。 +- `int next()` 返回嵌套列表的下一个整数。 +- `boolean hasNext()` 如果仍然存在待迭代的整数,返回 `true` ;否则,返回 `false` 。 + +你的代码将会用下述伪代码检测: + +> ```js +> initialize iterator with nestedList +> res = [] +> while iterator.hasNext() +> append iterator.next() to the end of res +> return res +> ``` + +如果 `res` 与预期的扁平化列表匹配,那么你的代码将会被判为正确。 + +**示例 1:** + +> **输入:** nestedList = [[1,1],2,[1,1]] +> +> **输出:**[1,1,2,1,1] +> +> **解释:** 通过重复调用 _next_ 直到 _hasNex_ t 返回 false, *next *返回的元素的顺序应该是: [1,1,2,1,1]。 + +**示例 2:** + +> **输入:** nestedList = [1,[4,[6]]] +> +> **输出:**[1,4,6] +> +> **解释:** 通过重复调用 *next *直到 _hasNex_ t 返回 false, *next *返回的元素的顺序应该是: [1,4,6]。 + +**提示:** + +- `1 <= nestedList.length <= 500` +- 嵌套列表中的整数值在范围 `[-10^6, 10^6]` 内 + +## 解题思路 + +利用递归深度优先搜索(DFS)将嵌套列表展开为一个扁平化数组,随后通过两个指针进行迭代。 + +1. **初始化阶段** + + - 使用一个私有方法 `dfs()` 遍历嵌套列表,递归处理每个元素。 + - 如果是整数,直接加入结果数组。 + - 如果是列表,递归调用 `dfs()` 继续展开。 + - 最终将扁平化的结果存储在一个数组 `flatten` 中。 + +2. **`hasNext()` 方法** + + - 检查当前指针是否小于扁平化数组的长度。 + +3. **`next()` 方法** + + - 返回当前指针指向的整数,同时将指针向后移动。 + +#### 复杂度分析 + +- **时间复杂度**: + + - 初始化(`dfs`):需要遍历整个嵌套列表,时间复杂度为 `O(n)`,其中 `n` 是列表中所有整数和列表的总数。 + - `hasNext()` 和 `next()`:每次调用的时间复杂度为 `O(1)`。 + +- **空间复杂度**:`O(n)`,额外使用的空间为存储扁平化数组的空间。 + +## 代码 + +```javascript +class NestedIterator { + constructor(nestedList) { + this.cur = 0; // 当前指针 + this.flatten = this.dfs(nestedList); // 扁平化后的数组 + } + + // 深度优先搜索展开列表 + dfs(arr) { + let res = []; + for (let item of arr) { + if (item.isInteger()) { + // 如果是整数,直接加入结果数组 + res.push(item.getInteger()); + } else { + // 如果是列表,递归展开 + res.push(...this.dfs(item.getList())); + } + } + return res; + } + + // 判断是否还有下一个整数 + hasNext() { + return this.cur < this.flatten.length; + } + + // 返回当前整数并移动指针 + next() { + return this.flatten[this.cur++]; + } +} +``` + +## 相关题目 + + +| 题号 | 标题 | 题解 | 标签 | 难度 | 力扣 | +| :------: | :------ | :------: | :------ | :------: | :------: | +| 251 | 展开二维向量 🔒 | | [`设计`](/tag/design.md) [`数组`](/tag/array.md) [`双指针`](/tag/two-pointers.md) `1+` | 🟠 | [🀄️](https://leetcode.cn/problems/flatten-2d-vector) [🔗](https://leetcode.com/problems/flatten-2d-vector) | +| 281 | 锯齿迭代器 🔒 | | [`设计`](/tag/design.md) [`队列`](/tag/queue.md) [`数组`](/tag/array.md) `1+` | 🟠 | [🀄️](https://leetcode.cn/problems/zigzag-iterator) [🔗](https://leetcode.com/problems/zigzag-iterator) | +| 385 | 迷你语法分析器 | | [`栈`](/tag/stack.md) [`深度优先搜索`](/tag/depth-first-search.md) [`字符串`](/tag/string.md) | 🟠 | [🀄️](https://leetcode.cn/problems/mini-parser) [🔗](https://leetcode.com/problems/mini-parser) | +| 565 | 数组嵌套 | | [`深度优先搜索`](/tag/depth-first-search.md) [`数组`](/tag/array.md) | 🟠 | [🀄️](https://leetcode.cn/problems/array-nesting) [🔗](https://leetcode.com/problems/array-nesting) | \ No newline at end of file diff --git a/src/problem/0357.md b/src/problem/0357.md new file mode 100644 index 0000000000..592d047b1d --- /dev/null +++ b/src/problem/0357.md @@ -0,0 +1,119 @@ +--- +title: 357. 统计各位数字都不同的数字个数 +description: LeetCode 357. 统计各位数字都不同的数字个数题解,Count Numbers with Unique Digits,包含解题思路、复杂度分析以及完整的 JavaScript 代码实现。 +keywords: + - LeetCode + - 357. 统计各位数字都不同的数字个数 + - 统计各位数字都不同的数字个数 + - Count Numbers with Unique Digits + - 解题思路 + - 数学 + - 动态规划 + - 回溯 +--- + +# 357. 统计各位数字都不同的数字个数 + +🟠 Medium  🔖  [`数学`](/tag/math.md) [`动态规划`](/tag/dynamic-programming.md) [`回溯`](/tag/backtracking.md)  🔗 [`力扣`](https://leetcode.cn/problems/count-numbers-with-unique-digits) [`LeetCode`](https://leetcode.com/problems/count-numbers-with-unique-digits) + +## 题目 + +Given an integer `n`, return the count of all numbers with unique digits, `x`, +where `0 <= x < 10^n`. + +**Example 1:** + +> Input: n = 2 +> +> Output: 91 +> +> Explanation: The answer should be the total numbers in the range of 0 ≤ x < 100, excluding 11,22,33,44,55,66,77,88,99 + +**Example 2:** + +> Input: n = 0 +> +> Output: 1 + +**Constraints:** + +- `0 <= n <= 8` + +## 题目大意 + +给你一个整数 `n` ,统计并返回各位数字都不同的数字 `x` 的个数,其中 `0 <= x < 10^n` 。 + +**示例 1:** + +> **输入:** n = 2 +> +> **输出:** 91 +> +> **解释:** 答案应为除去 11、22、33、44、55、66、77、88、99 外,在 0 ≤ x < 100 范围内的所有数字。 + +**示例 2:** + +> **输入:** n = 0 +> +> **输出:** 1 + +**提示:** + +- `0 <= n <= 8` + +## 解题思路 + +1. **`n == 0` 的特殊情况**: + + - 只有一个数字 `0`,答案为 `1`。 + +2. **枚举长度为 1 到 `n` 的所有数字**: + + - 长度为 1 的数字:`10` 个(`0` 到 `9`)。 + - 长度为 2 的数字:第一位有 `9` 种选择(不能为 `0`),第二位有 `9` 种选择(不能与第一位重复),共 `9 * 9`。 + - 长度为 3 的数字:第一位有 `9` 种选择,第二位有 `9` 种,第三位有 `8` 种(共 `9 * 9 * 8`)。 + - 依次类推。 + +3. **公式化计算**: + + - 对于长度为 `k` 的数字,总的不同数字个数为: + `9 * 9 * 8 * ... * (10 - k + 1)` + - 累加所有长度为 `1` 到 `n` 的结果即可。 + - 使用循环递推的方式计算每个长度的值,避免直接递归导致的额外开销。 + +#### 时间复杂度 + +- **时间复杂度**:`O(n)`,因为我们最多只计算 `n` 个长度的结果。 +- **空间复杂度**:`O(1)`,仅使用常数额外空间。 + +## 代码 + +```javascript +/** + * @param {number} n + * @return {number} + */ +var countNumbersWithUniqueDigits = function (n) { + if (n === 0) return 1; // 特殊情况 + + let res = 10; // 包含长度为 1 的数字(0 到 9) + let unique = 9; // 从第二位开始的独特数字组合数 + let availableNumber = 9; // 可供选择的数字数量 + + while (n-- > 1 && availableNumber > 0) { + unique *= availableNumber; // 更新当前长度的独特组合数 + res += unique; // 累加结果 + availableNumber--; // 剩余可选数字减少 + } + + return res; +}; +``` + +## 相关题目 + + +| 题号 | 标题 | 题解 | 标签 | 难度 | 力扣 | +| :------: | :------ | :------: | :------ | :------: | :------: | +| 2376 | 统计特殊整数 | | [`数学`](/tag/math.md) [`动态规划`](/tag/dynamic-programming.md) | 🔴 | [🀄️](https://leetcode.cn/problems/count-special-integers) [🔗](https://leetcode.com/problems/count-special-integers) | +| 3032 | 统计各位数字都不同的数字个数 II 🔒 | | [`哈希表`](/tag/hash-table.md) [`数学`](/tag/math.md) [`动态规划`](/tag/dynamic-programming.md) | 🟢 | [🀄️](https://leetcode.cn/problems/count-numbers-with-unique-digits-ii) [🔗](https://leetcode.com/problems/count-numbers-with-unique-digits-ii) | \ No newline at end of file diff --git a/src/problem/0407.md b/src/problem/0407.md new file mode 100644 index 0000000000..96591b0c70 --- /dev/null +++ b/src/problem/0407.md @@ -0,0 +1,248 @@ +--- +title: 407. 接雨水 II +description: LeetCode 407. 接雨水 II题解,Trapping Rain Water II,包含解题思路、复杂度分析以及完整的 JavaScript 代码实现。 +keywords: + - LeetCode + - 407. 接雨水 II + - 接雨水 II + - Trapping Rain Water II + - 解题思路 + - 广度优先搜索 + - 数组 + - 矩阵 + - 堆(优先队列) +--- + +# 407. 接雨水 II + +🔴 Hard  🔖  [`广度优先搜索`](/tag/breadth-first-search.md) [`数组`](/tag/array.md) [`矩阵`](/tag/matrix.md) [`堆(优先队列)`](/tag/heap-priority-queue.md)  🔗 [`力扣`](https://leetcode.cn/problems/trapping-rain-water-ii) [`LeetCode`](https://leetcode.com/problems/trapping-rain-water-ii) + +## 题目 + +Given an `m x n` integer matrix `heightMap` representing the height of each +unit cell in a 2D elevation map, return _the volume of water it can trap after +raining_. + +**Example 1:** + +![](https://assets.leetcode.com/uploads/2021/04/08/trap1-3d.jpg) + +> Input: heightMap = [[1,4,3,1,3,2],[3,2,1,3,2,4],[2,3,3,2,3,1]] +> +> Output: 4 +> +> Explanation: After the rain, water is trapped between the blocks. +> +> We have two small ponds 1 and 3 units trapped. +> +> The total volume of water trapped is 4. + +**Example 2:** + +![](https://assets.leetcode.com/uploads/2021/04/08/trap2-3d.jpg) + +> Input: heightMap = [[3,3,3,3,3],[3,2,2,2,3],[3,2,1,2,3],[3,2,2,2,3],[3,3,3,3,3]] +> +> Output: 10 + +**Constraints:** + +- `m == heightMap.length` +- `n == heightMap[i].length` +- `1 <= m, n <= 200` +- `0 <= heightMap[i][j] <= 2 * 10^4` + +## 题目大意 + +给你一个 `m x n` 的矩阵,其中的值均为非负整数,代表二维高度图每个单元的高度,请计算图中形状最多能接多少体积的雨水。 + +**示例 1:** + +![](https://assets.leetcode.com/uploads/2021/04/08/trap1-3d.jpg) + +> **输入:** heightMap = [[1,4,3,1,3,2],[3,2,1,3,2,4],[2,3,3,2,3,1]] +> +> **输出:** 4 +> +> **解释:** 下雨后,雨水将会被上图蓝色的方块中。总的接雨水量为 1+2+1=4。 + +**示例 2:** + +![](https://assets.leetcode.com/uploads/2021/04/08/trap2-3d.jpg) + +> **输入:** heightMap = [[3,3,3,3,3],[3,2,2,2,3],[3,2,1,2,3],[3,2,2,2,3],[3,3,3,3,3]] +> +> **输出:** 10 + +**提示:** + +- `m == heightMap.length` +- `n == heightMap[i].length` +- `1 <= m, n <= 200` +- `0 <= heightMap[i][j] <= 2 * 10^4` + +## 解题思路 + +这道题核心思想是利用最小堆(优先队列)来模拟水位从低向高逐步扩展的过程,逐步计算可储存的水量。 + +- 每个单元格的储水量由其周围的最低边界决定。储水量取决于该单元格的高度与最低边界高度的差值。 +- 如果边界较低,则水会从边界流出,因此边界单元格不储水。 + +**1. 初始化边界** + +- 矩阵过小(`m < 3` 或 `n < 3`)时无法储水,应直接返回 0。 +- 使用二维布尔数组 `visited` 避免重复访问同一单元格。 +- 首先将矩阵四周的边界单元格加入最小堆(优先队列),并标记为已访问。 +- 边界单元格作为初始水位的最低边界,确保优先处理低高度的单元格,模拟水从低到高扩展的过程。 + +**2. 使用最小堆模拟水位扩展** + +- 每次从最小堆中取出一个高度最小的单元格,作为当前水位。 +- 检查其四个相邻单元格: + - 如果该相邻单元格未访问,则根据当前单元格的高度计算是否可以储水。 + - 如果可以储水,将储水量累加,并将相邻单元格加入堆中,更新为较高的水位。 + +**3. 更新堆** + +- 对每个相邻单元格,将其高度更新为两者之间的较大值(模拟水位提升的过程)。 +- 将相邻单元格加入最小堆,以便下一次处理更低的单元格。 + +**4. 终止条件** + +- 当堆为空时,表示所有可以储水的单元格都已处理,返回累积的水量。 + +#### 复杂度分析 + +- **时间复杂度**:`O(m * n * log(m * n))`,每个单元格最多访问一次,堆的操作复杂度为 `O(log(m * n))`。 +- **空间复杂度**:`O(m * n)`,最小堆和访问标记数组各占用 `O(m * n)` 空间。 + +## 代码 + +```javascript +/** + * @param {number[][]} heightMap + * @return {number} + */ +var trapRainWater = function (heightMap) { + const m = heightMap.length; + const n = heightMap[0].length; + if (m < 3 || n < 3) return 0; + + const visited = new Array(m).fill().map(() => new Array(n).fill(false)); + + const priority = (a, b) => a[0] < b[0]; + const minHeap = new MinHeap([], priority); + + for (let i = 0; i < m; i++) { + minHeap.insert([heightMap[i][0], i, 0]); + minHeap.insert([heightMap[i][n - 1], i, n - 1]); + visited[i][0] = visited[i][n - 1] = true; + } + + for (let j = 1; j < n - 1; j++) { + minHeap.insert([heightMap[0][j], 0, j]); + minHeap.insert([heightMap[m - 1][j], m - 1, j]); + visited[0][j] = visited[m - 1][j] = true; + } + + const dirc = [ + [0, 1], + [0, -1], + [1, 0], + [-1, 0] + ]; + + let water = 0; + while (minHeap.size()) { + const [height, x, y] = minHeap.pop(); + for (let [dx, dy] of dirc) { + const nx = x + dx; + const ny = y + dy; + + if (nx < 0 || nx >= m || ny < 0 || ny >= n || visited[nx][ny]) { + continue; + } + + water += Math.max(0, height - heightMap[nx][ny]); + minHeap.insert([Math.max(height, heightMap[nx][ny]), nx, ny]); + visited[nx][ny] = true; + } + } + + return water; +}; + +// 最小优先队列 +class MinHeap { + constructor(arr = [], priority = (a, b) => a < b) { + this.heap = arr; + this.priority = priority; + for (let i = Math.floor(this.heap.length / 2) - 1; i >= 0; i--) { + this.heapifyDown(i); + } + } + + insert(num) { + this.heap.push(num); + this.heapifyUp(this.heap.length - 1); + } + + pop() { + if (this.heap.length === 0) return null; + const top = this.heap[0]; + const last = this.heap.pop(); + if (this.heap.length > 0) { + this.heap[0] = last; + this.heapifyDown(0); + } + return top; + } + + size() { + return this.heap.length; + } + + toArray() { + return this.heap; + } + + heapifyDown(i) { + const n = this.heap.length; + const left = 2 * i + 1; + const right = 2 * i + 2; + let smallest = i; + + if (left < n && this.priority(this.heap[left], this.heap[smallest])) { + smallest = left; + } + if (right < n && this.priority(this.heap[right], this.heap[smallest])) { + smallest = right; + } + + if (smallest !== i) { + [this.heap[i], this.heap[smallest]] = [this.heap[smallest], this.heap[i]]; + this.heapifyDown(smallest); + } + } + + heapifyUp(i) { + while (i > 0) { + const parent = Math.floor((i - 1) / 2); + if (this.priority(this.heap[i], this.heap[parent])) { + [this.heap[i], this.heap[parent]] = [this.heap[parent], this.heap[i]]; + i = parent; + } else { + break; + } + } + } +} +``` + +## 相关题目 + + +| 题号 | 标题 | 题解 | 标签 | 难度 | 力扣 | +| :------: | :------ | :------: | :------ | :------: | :------: | +| 42 | 接雨水 | [[✓]](/problem/0042.md) | [`栈`](/tag/stack.md) [`数组`](/tag/array.md) [`双指针`](/tag/two-pointers.md) `2+` | 🔴 | [🀄️](https://leetcode.cn/problems/trapping-rain-water) [🔗](https://leetcode.com/problems/trapping-rain-water) | +| 2503 | 矩阵查询可获得的最大分数 | | [`广度优先搜索`](/tag/breadth-first-search.md) [`并查集`](/tag/union-find.md) [`数组`](/tag/array.md) `4+` | 🔴 | [🀄️](https://leetcode.cn/problems/maximum-number-of-points-from-grid-queries) [🔗](https://leetcode.com/problems/maximum-number-of-points-from-grid-queries) | \ No newline at end of file diff --git a/src/problem/1267.md b/src/problem/1267.md new file mode 100644 index 0000000000..399a2dbdc7 --- /dev/null +++ b/src/problem/1267.md @@ -0,0 +1,174 @@ +--- +title: 1267. 统计参与通信的服务器 +description: LeetCode 1267. 统计参与通信的服务器题解,Count Servers that Communicate,包含解题思路、复杂度分析以及完整的 JavaScript 代码实现。 +keywords: + - LeetCode + - 1267. 统计参与通信的服务器 + - 统计参与通信的服务器 + - Count Servers that Communicate + - 解题思路 + - 深度优先搜索 + - 广度优先搜索 + - 并查集 + - 数组 + - 计数 + - 矩阵 +--- + +# 1267. 统计参与通信的服务器 + +🟠 Medium  🔖  [`深度优先搜索`](/tag/depth-first-search.md) [`广度优先搜索`](/tag/breadth-first-search.md) [`并查集`](/tag/union-find.md) [`数组`](/tag/array.md) [`计数`](/tag/counting.md) [`矩阵`](/tag/matrix.md)  🔗 [`力扣`](https://leetcode.cn/problems/count-servers-that-communicate) [`LeetCode`](https://leetcode.com/problems/count-servers-that-communicate) + +## 题目 + +You are given a map of a server center, represented as a `m * n` integer +matrix `grid`, where 1 means that on that cell there is a server and 0 means +that it is no server. Two servers are said to communicate if they are on the +same row or on the same column. + +Return the number of servers that communicate with any other server. + +**Example 1:** + +![](https://assets.leetcode.com/uploads/2019/11/14/untitled-diagram-6.jpg) + +> Input: grid = [[1,0],[0,1]] +> +> Output: 0 +> +> Explanation: No servers can communicate with others. + +**Example 2:** + +**![](https://assets.leetcode.com/uploads/2019/11/13/untitled-diagram-4.jpg)** + +> Input: grid = [[1,0],[1,1]] +> +> Output: 3 +> +> Explanation: All three servers can communicate with at least one other server. + +**Example 3:** + +![](https://assets.leetcode.com/uploads/2019/11/14/untitled-diagram-1-3.jpg) + +> Input: grid = [[1,1,0,0],[0,0,1,0],[0,0,1,0],[0,0,0,1]] +> +> Output: 4 +> +> Explanation: The two servers in the first row can communicate with each other. The two servers in the third column can communicate with each other. The server at right bottom corner can't communicate with any other server. + +**Constraints:** + +- `m == grid.length` +- `n == grid[i].length` +- `1 <= m <= 250` +- `1 <= n <= 250` +- `grid[i][j] == 0 or 1` + +## 题目大意 + +这里有一幅服务器分布图,服务器的位置标识在 `m * n` 的整数矩阵网格 `grid` 中,1 表示单元格上有服务器,0 表示没有。 + +如果两台服务器位于同一行或者同一列,我们就认为它们之间可以进行通信。 + +请你统计并返回能够与至少一台其他服务器进行通信的服务器的数量。 + +**示例 1:** + +![](https://assets.leetcode-cn.com/aliyun-lc- +upload/uploads/2019/11/24/untitled-diagram-6.jpg) + +> **输入:** grid = [[1,0],[0,1]] +> +> **输出:** 0 +> +> **解释:** 没有一台服务器能与其他服务器进行通信。 + +**示例 2:** + +**![](https://assets.leetcode-cn.com/aliyun-lc- +upload/uploads/2019/11/24/untitled-diagram-4-1.jpg)** + +> **输入:** grid = [[1,0],[1,1]] +> +> **输出:** 3 +> +> **解释:** 所有这些服务器都至少可以与一台别的服务器进行通信。 + +**示例 3:** + +![](https://assets.leetcode-cn.com/aliyun-lc- +upload/uploads/2019/11/24/untitled-diagram-1-3.jpg) + +> **输入:** grid = [[1,1,0,0],[0,0,1,0],[0,0,1,0],[0,0,0,1]] +> +> **输出:** 4 +> +> **解释:** 第一行的两台服务器互相通信,第三列的两台服务器互相通信,但右下角的服务器无法与其他服务器通信。 + +**提示:** + +- `m == grid.length` +- `n == grid[i].length` +- `1 <= m <= 250` +- `1 <= n <= 250` +- `grid[i][j] == 0 or 1` + +## 解题思路 + +1. **统计行和列的服务器数量:** + - 遍历整个网格 `grid`。 + - 使用两个数组 `rows` 和 `cols` 分别记录每一行和每一列的服务器数量。 +2. **统计可以通信的服务器数量:** + - 再次遍历网格,判断每个服务器是否满足通信条件: + - 条件:`rows[i] > 1 || cols[j] > 1`。 + - 满足条件的服务器计入结果 `res`。 +3. **返回结果:** + - 输出可以通信的服务器数量。 + +#### 复杂度分析 + +- **时间复杂度**:`O(m * n)`,遍历两次网格。 +- **空间复杂度**:`O(m + n)`,额外使用的两个数组 `rows` 和 `cols`。 + +## 代码 + +```javascript +/** + * @param {number[][]} grid + * @return {number} + */ +var countServers = function (grid) { + if (grid == null || grid.length == 0) return 0; + + const m = grid.length; + const n = grid[0].length; + + // 初始化行和列计数 + const rows = new Array(m).fill(0); + const cols = new Array(n).fill(0); + + // 统计每行和每列的服务器数量 + for (let i = 0; i < m; i++) { + for (let j = 0; j < n; j++) { + if (grid[i][j] === 1) { + rows[i]++; + cols[j]++; + } + } + } + + // 统计可以通信的服务器数量 + let res = 0; + for (let i = 0; i < m; i++) { + for (let j = 0; j < n; j++) { + if (grid[i][j] === 1 && (rows[i] > 1 || cols[j] > 1)) { + res++; + } + } + } + + return res; +}; +``` diff --git a/src/problem/1765.md b/src/problem/1765.md new file mode 100644 index 0000000000..ccaea61e2e --- /dev/null +++ b/src/problem/1765.md @@ -0,0 +1,218 @@ +--- +title: 1765. 地图中的最高点 +description: LeetCode 1765. 地图中的最高点题解,Map of Highest Peak,包含解题思路、复杂度分析以及完整的 JavaScript 代码实现。 +keywords: + - LeetCode + - 1765. 地图中的最高点 + - 地图中的最高点 + - Map of Highest Peak + - 解题思路 + - 广度优先搜索 + - 数组 + - 矩阵 +--- + +# 1765. 地图中的最高点 + +🟠 Medium  🔖  [`广度优先搜索`](/tag/breadth-first-search.md) [`数组`](/tag/array.md) [`矩阵`](/tag/matrix.md)  🔗 [`力扣`](https://leetcode.cn/problems/map-of-highest-peak) [`LeetCode`](https://leetcode.com/problems/map-of-highest-peak) + +## 题目 + +You are given an integer matrix `isWater` of size `m x n` that represents a +map of **land** and **water** cells. + +- If `isWater[i][j] == 0`, cell `(i, j)` is a **land** cell. +- If `isWater[i][j] == 1`, cell `(i, j)` is a **water** cell. + +You must assign each cell a height in a way that follows these rules: + +- The height of each cell must be non-negative. +- If the cell is a **water** cell, its height must be `0`. +- Any two adjacent cells must have an absolute height difference of **at most** `1`. A cell is adjacent to another cell if the former is directly north, east, south, or west of the latter (i.e., their sides are touching). + +Find an assignment of heights such that the maximum height in the matrix is +**maximized**. + +Return _an integer matrix_`height` _of size_`m x n` _where_`height[i][j]`_is cell_ `(i, j)` _' s height. If there are multiple solutions, return **any** of them_. + +**Example 1:** + +**![](https://assets.leetcode.com/uploads/2021/01/10/screenshot-2021-01-11-at-82045-am.png)** + +> Input: isWater = [[0,1],[0,0]] +> +> Output: [[1,0],[2,1]] +> +> Explanation: The image shows the assigned heights of each cell. +> +> The blue cell is the water cell, and the green cells are the land cells. + +**Example 2:** + +**![](https://assets.leetcode.com/uploads/2021/01/10/screenshot-2021-01-11-at-82050-am.png)** + +> Input: isWater = [[0,0,1],[1,0,0],[0,0,0]] +> +> Output: [[1,1,0],[0,1,1],[1,2,2]] +> +> Explanation: A height of 2 is the maximum possible height of any assignment. +> +> Any height assignment that has a maximum height of 2 while still meeting the rules will also be accepted. + +**Constraints:** + +- `m == isWater.length` +- `n == isWater[i].length` +- `1 <= m, n <= 1000` +- `isWater[i][j]` is `0` or `1`. +- There is at least **one** water cell. + +## 题目大意 + +给你一个大小为 `m x n` 的整数矩阵 `isWater` ,它代表了一个由 **陆地** 和 **水域** 单元格组成的地图。 + +- 如果 `isWater[i][j] == 0` ,格子 `(i, j)` 是一个 **陆地** 格子。 +- 如果 `isWater[i][j] == 1` ,格子 `(i, j)` 是一个 **水域** 格子。 + +你需要按照如下规则给每个单元格安排高度: + +- 每个格子的高度都必须是非负的。 +- 如果一个格子是 **水域** ,那么它的高度必须为 `0` 。 +- 任意相邻的格子高度差 **至多** 为 `1` 。当两个格子在正东、南、西、北方向上相互紧挨着,就称它们为相邻的格子。(也就是说它们有一条公共边) + +找到一种安排高度的方案,使得矩阵中的最高高度值 **最大** 。 + +请你返回一个大小为 `m x n` 的整数矩阵 `height` ,其中 `height[i][j]` 是格子 `(i, j)` +的高度。如果有多种解法,请返回 **任意一个** 。 + +**示例 1:** + +**![](https://assets.leetcode.com/uploads/2021/01/10/screenshot-2021-01-11-at-82045-am.png)** + +> **输入:** isWater = [[0,1],[0,0]] +> +> **输出:**[[1,0],[2,1]] +> +> **解释:** 上图展示了给各个格子安排的高度。 +> +> 蓝色格子是水域格,绿色格子是陆地格。 + +**示例 2:** + +**![](https://assets.leetcode.com/uploads/2021/01/10/screenshot-2021-01-11-at-82050-am.png)** + +> **输入:** isWater = [[0,0,1],[1,0,0],[0,0,0]] +> +> **输出:**[[1,1,0],[0,1,1],[1,2,2]] +> +> **解释:** 所有安排方案中,最高可行高度为 2 。 +> +> 任意安排方案中,只要最高高度为 2 且符合上述规则的,都为可行方案。 + +**提示:** + +- `m == isWater.length` +- `n == isWater[i].length` +- `1 <= m, n <= 1000` +- `isWater[i][j]` 要么是 `0` ,要么是 `1` 。 +- 至少有 **1** 个水域格子。 + +## 解题思路 + +### 解题思路 + +可以采用广度优先搜索(BFS)策略,将每个水源格子作为 BFS 的起点,逐步向外扩展,更新每个格子的高度为其与水源的距离,同时结合 **Deque** 来优化性能。 + +1. **初始化:** + - 创建结果数组 `res`,初始值为 `-1`,表示尚未访问的格子。 + - 将所有水源格子(值为 `1`)入队,初始高度设为 `0`。 +2. **双端队列:** + - 使用双端队列(Deque)来代替原生数组模拟队列。 + - **队首指针 (`head`):** 用于取出元素,完成 `shift` 操作。 + - **队尾指针 (`tail`):** 用于插入元素,完成 `push` 操作。 + - **性能优势:** 原生数组的 `shift` 是 `O(n)`,在高频操作下显著拖累性能。使用 `Deque` 实现的队列,`push` 和 `shift` 均为 `O(1)`。 +3. **广度优先搜索:** + - 每次从队首取出一个格子,尝试向四个方向扩展。 + - 对于未访问过的格子(`res` 值为 `-1`),将其高度设为当前高度 + 1,并加入队列。 +4. **终止条件:** + - 队列为空时,所有格子均已访问,搜索结束。 +5. **返回结果:** + - 输出构建好的结果数组。 + +#### 复杂度分析 + +- **时间复杂度**:`O(m * n)`,BFS 遍历每个格子一次。 +- **空间复杂度**:`O(m * n)`,结果数组和队列占用的存储空间。 + +## 代码 + +```javascript +/** + * @param {number[][]} isWater + * @return {number[][]} + */ +var highestPeak = function (isWater) { + const m = isWater.length; + const n = isWater[0].length; + + const res = Array.from({ length: m }, () => Array(n).fill(-1)); + const queue = new MyDeque(); + + // 初始化水源点 + for (let i = 0; i < m; i++) { + for (let j = 0; j < n; j++) { + if (isWater[i][j] === 1) { + queue.push([i, j]); // 双端队列尾部插入 + res[i][j] = 0; + } + } + } + + const directions = [ + [1, 0], + [-1, 0], + [0, 1], + [0, -1] + ]; + + // 广度优先搜索 + while (!queue.isEmpty()) { + const [x, y] = queue.shift(); // 双端队列头部取出 + for (const [dx, dy] of directions) { + const nx = x + dx; + const ny = y + dy; + // 检查边界并判断是否已访问 + if (nx >= 0 && nx < m && ny >= 0 && ny < n && res[nx][ny] === -1) { + res[nx][ny] = res[x][y] + 1; + queue.push([nx, ny]); // 双端队列尾部插入 + } + } + } + + return res; +}; + +// 定义简单的双端队列类 +class MyDeque { + constructor() { + this.data = []; + this.head = 0; // 队首指针 + this.tail = 0; // 队尾指针 + } + + push(value) { + this.data[this.tail++] = value; // 插入队尾 + } + + shift() { + if (this.isEmpty()) return null; + const value = this.data[this.head]; + this.head++; + return value; // 取出队首 + } + + isEmpty() { + return this.head === this.tail; + } +} +``` diff --git a/src/problem/2017.md b/src/problem/2017.md new file mode 100644 index 0000000000..50593de08d --- /dev/null +++ b/src/problem/2017.md @@ -0,0 +1,203 @@ +--- +title: 2017. 网格游戏 +description: LeetCode 2017. 网格游戏题解,Grid Game,包含解题思路、复杂度分析以及完整的 JavaScript 代码实现。 +keywords: + - LeetCode + - 2017. 网格游戏 + - 网格游戏 + - Grid Game + - 解题思路 + - 数组 + - 矩阵 + - 前缀和 +--- + +# 2017. 网格游戏 + +🟠 Medium  🔖  [`数组`](/tag/array.md) [`矩阵`](/tag/matrix.md) [`前缀和`](/tag/prefix-sum.md)  🔗 [`力扣`](https://leetcode.cn/problems/grid-game) [`LeetCode`](https://leetcode.com/problems/grid-game) + +## 题目 + +You are given a **0-indexed** 2D array `grid` of size `2 x n`, where +`grid[r][c]` represents the number of points at position `(r, c)` on the +matrix. Two robots are playing a game on this matrix. + +Both robots initially start at `(0, 0)` and want to reach `(1, n-1)`. Each +robot may only move to the **right** (`(r, c)` to `(r, c + 1)`) or +**down**(`(r, c)` to `(r + 1, c)`). + +At the start of the game, the **first** robot moves from `(0, 0)` to `(1, +n-1)`, collecting all the points from the cells on its path. For all cells +`(r, c)` traversed on the path, `grid[r][c]` is set to `0`. Then, the +**second** robot moves from `(0, 0)` to `(1, n-1)`, collecting the points on +its path. Note that their paths may intersect with one another. + +The **first** robot wants to **minimize** the number of points collected by +the **second** robot. In contrast, the **second** robot wants to **maximize** +the number of points it collects. If both robots play **optimally** , return +_the**number of points** collected by the **second** robot._ + +**Example 1:** + +![](https://assets.leetcode.com/uploads/2021/09/08/a1.png) + +> Input: grid = [[2,5,4],[1,5,1]] +> +> Output: 4 +> +> Explanation: The optimal path taken by the first robot is shown in red, and the optimal path taken by the second robot is shown in blue. +> +> The cells visited by the first robot are set to 0. +> +> The second robot will collect 0 + 0 + 4 + 0 = 4 points. + +**Example 2:** + +![](https://assets.leetcode.com/uploads/2021/09/08/a2.png) + +> Input: grid = [[3,3,1],[8,5,2]] +> +> Output: 4 +> +> Explanation: The optimal path taken by the first robot is shown in red, and the optimal path taken by the second robot is shown in blue. +> +> The cells visited by the first robot are set to 0. +> +> The second robot will collect 0 + 3 + 1 + 0 = 4 points. + +**Example 3:** + +![](https://assets.leetcode.com/uploads/2021/09/08/a3.png) + +> Input: grid = [[1,3,1,15],[1,3,3,1]] +> +> Output: 7 +> +> Explanation: The optimal path taken by the first robot is shown in red, and the optimal path taken by the second robot is shown in blue. +> +> The cells visited by the first robot are set to 0. +> +> The second robot will collect 0 + 1 + 3 + 3 + 0 = 7 points. + +**Constraints:** + +- `grid.length == 2` +- `n == grid[r].length` +- `1 <= n <= 5 * 10^4` +- `1 <= grid[r][c] <= 10^5` + +## 题目大意 + +给你一个下标从 **0** 开始的二维数组 `grid` ,数组大小为 `2 x n` ,其中 `grid[r][c]` 表示矩阵中 `(r, c)` +位置上的点数。现在有两个机器人正在矩阵上参与一场游戏。 + +两个机器人初始位置都是 `(0, 0)` ,目标位置是 `(1, n-1)` 。每个机器人只会 **向右** (`(r, c)` 到 `(r, c + +1)`) 或 **向下**(`(r, c)` 到 `(r + 1, c)`) 。 + +游戏开始,**第一个** 机器人从 `(0, 0)` 移动到 `(1, n-1)` ,并收集路径上单元格的全部点数。对于路径上所有单元格 `(r, c)` +,途经后 `grid[r][c]` 会重置为 `0` 。然后,**第二个** 机器人从 `(0, 0)` 移动到 `(1, n-1)` +,同样收集路径上单元的全部点数。注意,它们的路径可能会存在相交的部分。 + +**第一个** 机器人想要打击竞争对手,使 **第二个** 机器人收集到的点数 **最小化** 。与此相对,**第二个** 机器人想要 **最大化** +自己收集到的点数。两个机器人都发挥出自己的 **最佳水平** 的前提下,返回 **第二个** 机器人收集到的 **点数** 。 + +**示例 1:** + +![](https://assets.leetcode.com/uploads/2021/09/08/a1.png) + +> **输入:** grid = [[2,5,4],[1,5,1]] +> +> **输出:** 4 +> +> **解释:** 第一个机器人的最佳路径如红色所示,第二个机器人的最佳路径如蓝色所示。 +> +> 第一个机器人访问过的单元格将会重置为 0 。 +> +> 第二个机器人将会收集到 0 + 0 + 4 + 0 = 4 个点。 + +**示例 2:** + +![](https://assets.leetcode.com/uploads/2021/09/08/a2.png) + +> **输入:** grid = [[3,3,1],[8,5,2]] +> +> **输出:** 4 +> +> **解释:** 第一个机器人的最佳路径如红色所示,第二个机器人的最佳路径如蓝色所示。 +> +> 第一个机器人访问过的单元格将会重置为 0 。 +> +> 第二个机器人将会收集到 0 + 3 + 1 + 0 = 4 个点。 + +**示例 3:** + +![](https://assets.leetcode.com/uploads/2021/09/08/a3.png) + +> **输入:** grid = [[1,3,1,15],[1,3,3,1]] +> +> **输出:** 7 +> +> **解释:** 第一个机器人的最佳路径如红色所示,第二个机器人的最佳路径如蓝色所示。 +> +> 第一个机器人访问过的单元格将会重置为 0 。 +> +> 第二个机器人将会收集到 0 + 1 + 3 + 3 + 0 = 7 个点。 + +**提示:** + +- `grid.length == 2` +- `n == grid[r].length` +- `1 <= n <= 5 * 10^4` +- `1 <= grid[r][c] <= 10^5` + +## 解题思路 + +玩家 1 选择路径后,玩家 2 需要选择一条与玩家 1 路径不重叠的路径。 + +玩家 2 的路径只能走玩家 1 路径的剩余部分(上行或下行),因此我们只需计算玩家 2 在这两种情况下的分数即可。 + +1. 使用前缀和计算两个方向的路径和: + + - `firstRowSum` 表示玩家 1 从当前列之后(包括当前列)向右的总和。 + - `secondRowSum` 表示玩家 1 从当前列之前(不包括当前列)向左的总和。 + +2. 遍历每个列,假设玩家 1 切换路径的分割点为当前列 `i`,计算以下两种情况的分数: + + - 玩家 2 向右选择剩余的第一行路径分数(`firstRowSum`)。 + - 玩家 2 向左选择第二行路径分数(`secondRowSum`)。 + +3. 对于每一列,玩家 2 的分数是 `max(firstRowSum, secondRowSum)`(即选择路径时的最坏情况),我们需要找到这种分数的最小值。 + +#### 复杂度分析 + +- **时间复杂度**:`O(n)`,其中 `n` 是列数,遍历一遍网格的列。 +- **空间复杂度**:`O(1)`,使用常数级变量。 + +## 代码 + +```javascript +/** + * @param {number[][]} grid + * @return {number} + */ +var gridGame = function (grid) { + let firstRowSum = grid[0].reduce((a, b) => a + b, 0); // 第一行总和 + let secondRowSum = 0; // 第二行初始累积和 + let minSum = Infinity; // 玩家 2 的最小可能分数 + + for (let i = 0; i < grid[0].length; i++) { + firstRowSum -= grid[0][i]; // 从第一行总和中减去当前列的值 + minSum = Math.min(minSum, Math.max(firstRowSum, secondRowSum)); // 玩家 2 的最大分数(选择最优路径) + secondRowSum += grid[1][i]; // 累加第二行的值 + } + + return minSum; +}; +``` + +## 相关题目 + + +| 题号 | 标题 | 题解 | 标签 | 难度 | 力扣 | +| :------: | :------ | :------: | :------ | :------: | :------: | +| 2483 | 商店的最少代价 | | [`字符串`](/tag/string.md) [`前缀和`](/tag/prefix-sum.md) | 🟠 | [🀄️](https://leetcode.cn/problems/minimum-penalty-for-a-shop) [🔗](https://leetcode.com/problems/minimum-penalty-for-a-shop) | \ No newline at end of file diff --git a/src/problem/2133.md b/src/problem/2133.md index cc88e93c33..0aa6040522 100644 --- a/src/problem/2133.md +++ b/src/problem/2133.md @@ -142,4 +142,4 @@ var checkValid = function (matrix) { | :------: | :------ | :------: | :------ | :------: | :------: | | 36 | 有效的数独 | [[✓]](/problem/0036.md) | [`数组`](/tag/array.md) [`哈希表`](/tag/hash-table.md) [`矩阵`](/tag/matrix.md) | 🟠 | [🀄️](https://leetcode.cn/problems/valid-sudoku) [🔗](https://leetcode.com/problems/valid-sudoku) | | 1572 | 矩阵对角线元素的和 | [[✓]](/problem/1572.md) | [`数组`](/tag/array.md) [`矩阵`](/tag/matrix.md) | 🟢 | [🀄️](https://leetcode.cn/problems/matrix-diagonal-sum) [🔗](https://leetcode.com/problems/matrix-diagonal-sum) | -| 2661 | 找出叠涂元素 | | [`数组`](/tag/array.md) [`哈希表`](/tag/hash-table.md) [`矩阵`](/tag/matrix.md) | 🟠 | [🀄️](https://leetcode.cn/problems/first-completely-painted-row-or-column) [🔗](https://leetcode.com/problems/first-completely-painted-row-or-column) | \ No newline at end of file +| 2661 | 找出叠涂元素 | [[✓]](/problem/2661.md) | [`数组`](/tag/array.md) [`哈希表`](/tag/hash-table.md) [`矩阵`](/tag/matrix.md) | 🟠 | [🀄️](https://leetcode.cn/problems/first-completely-painted-row-or-column) [🔗](https://leetcode.com/problems/first-completely-painted-row-or-column) | \ No newline at end of file diff --git a/src/problem/2661.md b/src/problem/2661.md new file mode 100644 index 0000000000..5c708af9fc --- /dev/null +++ b/src/problem/2661.md @@ -0,0 +1,177 @@ +--- +title: 2661. 找出叠涂元素 +description: LeetCode 2661. 找出叠涂元素题解,First Completely Painted Row or Column,包含解题思路、复杂度分析以及完整的 JavaScript 代码实现。 +keywords: + - LeetCode + - 2661. 找出叠涂元素 + - 找出叠涂元素 + - First Completely Painted Row or Column + - 解题思路 + - 数组 + - 哈希表 + - 矩阵 +--- + +# 2661. 找出叠涂元素 + +🟠 Medium  🔖  [`数组`](/tag/array.md) [`哈希表`](/tag/hash-table.md) [`矩阵`](/tag/matrix.md)  🔗 [`力扣`](https://leetcode.cn/problems/first-completely-painted-row-or-column) [`LeetCode`](https://leetcode.com/problems/first-completely-painted-row-or-column) + +## 题目 + +You are given a **0-indexed** integer array `arr`, and an `m x n` integer +**matrix** `mat`. `arr` and `mat` both contain **all** the integers in the +range `[1, m * n]`. + +Go through each index `i` in `arr` starting from index `0` and paint the cell +in `mat` containing the integer `arr[i]`. + +Return _the smallest index_ `i` _at which either a row or a column will be +completely painted in_ `mat`. + +**Example 1:** + +![](image explanation for example 1)![image explanation for example +1](https://assets.leetcode.com/uploads/2023/01/18/grid1.jpg) + +> Input: arr = [1,3,4,2], mat = [[1,4],[2,3]] +> +> Output: 2 +> +> Explanation: The moves are shown in order, and both the first row and second column of the matrix become fully painted at arr[2]. + +**Example 2:** + +![image explanation for example +2](https://assets.leetcode.com/uploads/2023/01/18/grid2.jpg) + +> Input: arr = [2,8,7,4,1,3,5,6,9], mat = [[3,2,5],[1,4,6],[8,7,9]] +> +> Output: 3 +> +> Explanation: The second column becomes fully painted at arr[3]. + +**Constraints:** + +- `m == mat.length` +- `n = mat[i].length` +- `arr.length == m * n` +- `1 <= m, n <= 10^5` +- `1 <= m * n <= 10^5` +- `1 <= arr[i], mat[r][c] <= m * n` +- All the integers of `arr` are **unique**. +- All the integers of `mat` are **unique**. + +## 题目大意 + +给你一个下标从 **0** 开始的整数数组 `arr` 和一个 `m x n` 的整数 **矩阵** `mat` 。`arr` 和 `mat` 都包含范围 +`[1,m * n]` 内的 **所有** 整数。 + +从下标 `0` 开始遍历 `arr` 中的每个下标 `i` ,并将包含整数 `arr[i]` 的 `mat` 单元格涂色。 + +请你找出 `arr` 中第一个使得 `mat` 的某一行或某一列都被涂色的元素,并返回其下标 `i` 。 + +**示例 1:** + +![image explanation for example +1](https://assets.leetcode.com/uploads/2023/01/18/grid1.jpg) + +> **输入:** arr = [1,3,4,2], mat = [[1,4],[2,3]] +> +> **输出:** 2 +> +> **解释:** 遍历如上图所示,arr[2] 在矩阵中的第一行或第二列上都被涂色。 + +**示例 2:** + +![image explanation for example +2](https://assets.leetcode.com/uploads/2023/01/18/grid2.jpg) + +> **输入:** arr = [2,8,7,4,1,3,5,6,9], mat = [[3,2,5],[1,4,6],[8,7,9]] +> +> **输出:** 3 +> +> **解释:** 遍历如上图所示,arr[3] 在矩阵中的第二列上都被涂色。 + +**提示:** + +- `m == mat.length` +- `n = mat[i].length` +- `arr.length == m * n` +- `1 <= m, n <= 10^5` +- `1 <= m * n <= 10^5` +- `1 <= arr[i], mat[r][c] <= m * n` +- `arr` 中的所有整数 **互不相同** +- `mat` 中的所有整数 **互不相同** + +## 解题思路 + +1. **预处理:构建位置映射** + + - 将矩阵的每个值的行、列索引记录到一个哈希表中,以便快速找到 `arr[i]` 在矩阵中的位置。 + +2. **初始化计数数组** + + - 使用两个数组 `rowCount` 和 `colCount` 分别记录矩阵中每一行和每一列已涂色的单元格数。 + +3. **模拟涂色过程** + + - 遍历 `arr`,对于每个值,根据映射找到其在矩阵中的行和列索引。 + - 更新对应的 `rowCount` 和 `colCount`。 + - 检查当前行或列是否完全涂满,如果是,直接返回当前的操作步骤。 + +#### 复杂度分析 + +- **时间复杂度**:`O(m * n + k)` + - 预处理位置映射:`O(m * n)`,其中 `m` 和 `n` 分别是矩阵的行数和列数。 + - 模拟涂色过程:`O(k)`,`k` 是 `arr` 的长度。 + - 总复杂度为 `O(m * n + k)`。 +- **空间复杂度**:`O(m + n + m*n)`,使用了两个计数数组 `rowCount` 和 `colCount`,以及一个映射表。 + +## 代码 + +```javascript +/** + * @param {number[][]} grid + * @param {number[]} arr + * @return {number} + */ +var firstCompleteIndex = function (grid, arr) { + const m = grid.length, + n = grid[0].length; + + // 映射每个值到它在矩阵中的位置 + const valueToPosition = new Map(); + for (let i = 0; i < m; i++) { + for (let j = 0; j < n; j++) { + valueToPosition.set(grid[i][j], [i, j]); + } + } + + // 初始化行和列的计数器 + const rowCount = new Array(m).fill(0); + const colCount = new Array(n).fill(0); + + // 遍历数组,模拟涂色 + for (let step = 0; step < arr.length; step++) { + const value = arr[step]; + const [row, col] = valueToPosition.get(value); + + // 更新行和列的计数 + rowCount[row]++; + colCount[col]++; + + // 检查是否有行或列被完全涂满 + if (rowCount[row] === n || colCount[col] === m) { + return step; // 返回从 0 开始的索引 + } + } +}; +``` + +## 相关题目 + + +| 题号 | 标题 | 题解 | 标签 | 难度 | 力扣 | +| :------: | :------ | :------: | :------ | :------: | :------: | +| 2133 | 检查是否每一行每一列都包含全部整数 | [[✓]](/problem/2133.md) | [`数组`](/tag/array.md) [`哈希表`](/tag/hash-table.md) [`矩阵`](/tag/matrix.md) | 🟢 | [🀄️](https://leetcode.cn/problems/check-if-every-row-and-column-contains-all-numbers) [🔗](https://leetcode.com/problems/check-if-every-row-and-column-contains-all-numbers) | +| 2482 | 行和列中一和零的差值 | | [`数组`](/tag/array.md) [`矩阵`](/tag/matrix.md) [`模拟`](/tag/simulation.md) | 🟠 | [🀄️](https://leetcode.cn/problems/difference-between-ones-and-zeros-in-row-and-column) [🔗](https://leetcode.com/problems/difference-between-ones-and-zeros-in-row-and-column) | \ No newline at end of file diff --git a/src/problem/2683.md b/src/problem/2683.md new file mode 100644 index 0000000000..c39d218594 --- /dev/null +++ b/src/problem/2683.md @@ -0,0 +1,185 @@ +--- +title: 2683. 相邻值的按位异或 +description: LeetCode 2683. 相邻值的按位异或题解,Neighboring Bitwise XOR,包含解题思路、复杂度分析以及完整的 JavaScript 代码实现。 +keywords: + - LeetCode + - 2683. 相邻值的按位异或 + - 相邻值的按位异或 + - Neighboring Bitwise XOR + - 解题思路 + - 位运算 + - 数组 +--- + +# 2683. 相邻值的按位异或 + +🟠 Medium  🔖  [`位运算`](/tag/bit-manipulation.md) [`数组`](/tag/array.md)  🔗 [`力扣`](https://leetcode.cn/problems/neighboring-bitwise-xor) [`LeetCode`](https://leetcode.com/problems/neighboring-bitwise-xor) + +## 题目 + +A **0-indexed** array `derived` with length `n` is derived by computing the +**bitwise XOR** (⊕) of adjacent values in a **binary array** `original` of +length `n`. + +Specifically, for each index `i` in the range `[0, n - 1]`: + +- If `i = n - 1`, then `derived[i] = original[i] ⊕ original[0]`. +- Otherwise, `derived[i] = original[i] ⊕ original[i + 1]`. + +Given an array `derived`, your task is to determine whether there exists a +**valid binary array** `original` that could have formed `derived`. + +Return _**true** if such an array exists or **false** otherwise._ + +- A binary array is an array containing only **0 's** and **1 's** + +**Example 1:** + +> Input: derived = [1,1,0] +> +> Output: true +> +> Explanation: A valid original array that gives derived is [0,1,0]. +> +> derived[0] = original[0] ⊕ original[1] = 0 ⊕ 1 = 1 +> +> derived[1] = original[1] ⊕ original[2] = 1 ⊕ 0 = 1 +> +> derived[2] = original[2] ⊕ original[0] = 0 ⊕ 0 = 0 + +**Example 2:** + +> Input: derived = [1,1] +> +> Output: true +> +> Explanation: A valid original array that gives derived is [0,1]. +> +> derived[0] = original[0] ⊕ original[1] = 1 +> +> derived[1] = original[1] ⊕ original[0] = 1 + +**Example 3:** + +> Input: derived = [1,0] +> +> Output: false +> +> Explanation: There is no valid original array that gives derived. + +**Constraints:** + +- `n == derived.length` +- `1 <= n <= 10^5` +- The values in `derived` are either **0 's** or **1 's** + +## 题目大意 + +下标从 **0** 开始、长度为 `n` 的数组 `derived` 是由同样长度为 `n` 的原始 **二进制数组** `original` +通过计算相邻值的 **按位异或(⊕)** 派生而来。 + +特别地,对于范围 `[0, n - 1]` 内的每个下标 `i` : + +- 如果 `i = n - 1` ,那么 `derived[i] = original[i] ⊕ original[0]` +- 否则 `derived[i] = original[i] ⊕ original[i + 1]` + +给你一个数组 `derived` ,请判断是否存在一个能够派生得到 `derived` 的 **有效原始二进制数组** `original` 。 + +如果存在满足要求的原始二进制数组,返回 _**true**_;否则,返回 _**false**_。 + +- 二进制数组是仅由 **0** 和 **1** 组成的数组。 + +**示例 1:** + +> **输入:** derived = [1,1,0] +> +> **输出:** true +> +> **解释:** 能够派生得到 [1,1,0] 的有效原始二进制数组是 [0,1,0] : +> +> derived[0] = original[0] ⊕ original[1] = 0 ⊕ 1 = 1 +> +> derived[1] = original[1] ⊕ original[2] = 1 ⊕ 0 = 1 +> +> derived[2] = original[2] ⊕ original[0] = 0 ⊕ 0 = 0 + +**示例 2:** + +> **输入:** derived = [1,1] +> +> **输出:** true +> +> **解释:** 能够派生得到 [1,1] 的有效原始二进制数组是 [0,1] : +> +> derived[0] = original[0] ⊕ original[1] = 1 +> +> derived[1] = original[1] ⊕ original[0] = 1 + +**示例 3:** + +> **输入:** derived = [1,0] +> +> **输出:** false +> +> **解释:** 不存在能够派生得到 [1,0] 的有效原始二进制数组。 + +**提示:** + +- `n == derived.length` +- `1 <= n <= 10^5` +- `derived` 中的值不是 **0** 就是 **1** 。 + +## 解题思路 + +题目考察的是一个数组是否可以通过异或操作还原成有效的原始数组。关键点在于: + +1. 异或的性质: + - `a ^ b = c`,那么 `b = a ^ c`。 + - 因此,异或操作具有可逆性。 +2. 原始数组的有效性: + - 如果能形成一个循环的异或关系(即首尾元素连接后满足规则),那么原始数组是有效的。 + +由于数组是循环的,可以通过假设 `original[0]` 的初值为 `0` 或 `1` 两种情况进行模拟: + +1. **假设 1:`original[0] = 0`**: + - 根据公式 `derived[i] = original[i] ^ original[i + 1]` 推算整个数组。 + - 判断推导出的 `original` 是否有效(即形成闭环,满足 `original[n] = original[0]`)。 +2. **假设 2:`original[0] = 1`**: + - 同样推导数组并判断闭环条件。 + +如果任一假设成立,则返回 `true`;否则返回 `false`。 + +- 用两个变量 `case1` 和 `case2` 表示假设 `original[0] = 0` 和 `original[0] = 1` 的推导结果。 +- 遍历 `derived` 数组,用异或公式更新 `case1` 和 `case2`。 +- 判断最终结果是否满足闭环条件。 + +#### 复杂度分析 + +- **时间复杂度**:`O(n)`,只需遍历一次 `derived`。 +- **空间复杂度**:`O(1)`,使用常量空间。 + +## 代码 + +```javascript +/** + * @param {number[]} derived + * @return {boolean} + */ +var doesValidArrayExist = function (derived) { + let case1 = 0, // 假设 original[0] = 0 + case2 = 1; // 假设 original[0] = 1 + for (let num of derived) { + case1 = num ^ case1; + case2 = num ^ case2; + } + // 如果任一闭环成立,返回 true + return case1 === 0 || case2 === 1; +}; +``` + +## 相关题目 + + +| 题号 | 标题 | 题解 | 标签 | 难度 | 力扣 | +| :------: | :------ | :------: | :------ | :------: | :------: | +| 3173 | 相邻元素的按位或 🔒 | | [`位运算`](/tag/bit-manipulation.md) [`数组`](/tag/array.md) | 🟢 | [🀄️](https://leetcode.cn/problems/bitwise-or-of-adjacent-elements) [🔗](https://leetcode.com/problems/bitwise-or-of-adjacent-elements) | \ No newline at end of file diff --git a/src/problem/3203.md b/src/problem/3203.md index 7b414b0cb2..4d44ea4246 100644 --- a/src/problem/3203.md +++ b/src/problem/3203.md @@ -266,5 +266,5 @@ var getDiameter = function (edges) { | 题号 | 标题 | 题解 | 标签 | 难度 | 力扣 | | :------: | :------ | :------: | :------ | :------: | :------: | -| 310 | 最小高度树 | | [`深度优先搜索`](/tag/depth-first-search.md) [`广度优先搜索`](/tag/breadth-first-search.md) [`图`](/tag/graph.md) `1+` | 🟠 | [🀄️](https://leetcode.cn/problems/minimum-height-trees) [🔗](https://leetcode.com/problems/minimum-height-trees) | +| 310 | 最小高度树 | [[✓]](/problem/0310.md) | [`深度优先搜索`](/tag/depth-first-search.md) [`广度优先搜索`](/tag/breadth-first-search.md) [`图`](/tag/graph.md) `1+` | 🟠 | [🀄️](https://leetcode.cn/problems/minimum-height-trees) [🔗](https://leetcode.com/problems/minimum-height-trees) | | 1245 | 树的直径 🔒 | | [`树`](/tag/tree.md) [`深度优先搜索`](/tag/depth-first-search.md) [`广度优先搜索`](/tag/breadth-first-search.md) `2+` | 🟠 | [🀄️](https://leetcode.cn/problems/tree-diameter) [🔗](https://leetcode.com/problems/tree-diameter) | \ No newline at end of file diff --git a/src/problem/README.md b/src/problem/README.md index 2d582f342c..2e22e6f7af 100644 --- a/src/problem/README.md +++ b/src/problem/README.md @@ -1,6 +1,6 @@ # 目录 -已完成 961 道 +已完成 976 道 | 题号 | 标题 | 题解 | 标签 | 难度 | 力扣 | @@ -247,14 +247,22 @@ | 300 | 最长递增子序列 | [[✓]](/problem/0300.md) | [`数组`](/tag/array.md) [`二分查找`](/tag/binary-search.md) [`动态规划`](/tag/dynamic-programming.md) | 🟠 | [🀄️](https://leetcode.cn/problems/longest-increasing-subsequence) [🔗](https://leetcode.com/problems/longest-increasing-subsequence) | | 303 | 区域和检索 - 数组不可变 | [[✓]](/problem/0303.md) | [`设计`](/tag/design.md) [`数组`](/tag/array.md) [`前缀和`](/tag/prefix-sum.md) | 🟢 | [🀄️](https://leetcode.cn/problems/range-sum-query-immutable) [🔗](https://leetcode.com/problems/range-sum-query-immutable) | | 304 | 二维区域和检索 - 矩阵不可变 | [[✓]](/problem/0304.md) | [`设计`](/tag/design.md) [`数组`](/tag/array.md) [`矩阵`](/tag/matrix.md) `1+` | 🟠 | [🀄️](https://leetcode.cn/problems/range-sum-query-2d-immutable) [🔗](https://leetcode.com/problems/range-sum-query-2d-immutable) | +| 306 | 累加数 | [[✓]](/problem/0306.md) | [`字符串`](/tag/string.md) [`回溯`](/tag/backtracking.md) | 🟠 | [🀄️](https://leetcode.cn/problems/additive-number) [🔗](https://leetcode.com/problems/additive-number) | | 307 | 区域和检索 - 数组可修改 | [[✓]](/problem/0307.md) | [`设计`](/tag/design.md) [`树状数组`](/tag/binary-indexed-tree.md) [`线段树`](/tag/segment-tree.md) `1+` | 🟠 | [🀄️](https://leetcode.cn/problems/range-sum-query-mutable) [🔗](https://leetcode.com/problems/range-sum-query-mutable) | | 309 | 买卖股票的最佳时机含冷冻期 | [[✓]](/problem/0309.md) | [`数组`](/tag/array.md) [`动态规划`](/tag/dynamic-programming.md) | 🟠 | [🀄️](https://leetcode.cn/problems/best-time-to-buy-and-sell-stock-with-cooldown) [🔗](https://leetcode.com/problems/best-time-to-buy-and-sell-stock-with-cooldown) | +| 310 | 最小高度树 | [[✓]](/problem/0310.md) | [`深度优先搜索`](/tag/depth-first-search.md) [`广度优先搜索`](/tag/breadth-first-search.md) [`图`](/tag/graph.md) `1+` | 🟠 | [🀄️](https://leetcode.cn/problems/minimum-height-trees) [🔗](https://leetcode.com/problems/minimum-height-trees) | +| 313 | 超级丑数 | [[✓]](/problem/0313.md) | [`数组`](/tag/array.md) [`数学`](/tag/math.md) [`动态规划`](/tag/dynamic-programming.md) | 🟠 | [🀄️](https://leetcode.cn/problems/super-ugly-number) [🔗](https://leetcode.com/problems/super-ugly-number) | | 316 | 去除重复字母 | [[✓]](/problem/0316.md) | [`栈`](/tag/stack.md) [`贪心`](/tag/greedy.md) [`字符串`](/tag/string.md) `1+` | 🟠 | [🀄️](https://leetcode.cn/problems/remove-duplicate-letters) [🔗](https://leetcode.com/problems/remove-duplicate-letters) | +| 318 | 最大单词长度乘积 | [[✓]](/problem/0318.md) | [`位运算`](/tag/bit-manipulation.md) [`数组`](/tag/array.md) [`字符串`](/tag/string.md) | 🟠 | [🀄️](https://leetcode.cn/problems/maximum-product-of-word-lengths) [🔗](https://leetcode.com/problems/maximum-product-of-word-lengths) | +| 319 | 灯泡开关 | [[✓]](/problem/0319.md) | [`脑筋急转弯`](/tag/brainteaser.md) [`数学`](/tag/math.md) | 🟠 | [🀄️](https://leetcode.cn/problems/bulb-switcher) [🔗](https://leetcode.com/problems/bulb-switcher) | | 322 | 零钱兑换 | [[✓]](/problem/0322.md) | [`广度优先搜索`](/tag/breadth-first-search.md) [`数组`](/tag/array.md) [`动态规划`](/tag/dynamic-programming.md) | 🟠 | [🀄️](https://leetcode.cn/problems/coin-change) [🔗](https://leetcode.com/problems/coin-change) | | 326 | 3 的幂 | [[✓]](/problem/0326.md) | [`递归`](/tag/recursion.md) [`数学`](/tag/math.md) | 🟢 | [🀄️](https://leetcode.cn/problems/power-of-three) [🔗](https://leetcode.com/problems/power-of-three) | | 328 | 奇偶链表 | [[✓]](/problem/0328.md) | [`链表`](/tag/linked-list.md) | 🟠 | [🀄️](https://leetcode.cn/problems/odd-even-linked-list) [🔗](https://leetcode.com/problems/odd-even-linked-list) | +| 331 | 验证二叉树的前序序列化 | [[✓]](/problem/0331.md) | [`栈`](/tag/stack.md) [`树`](/tag/tree.md) [`字符串`](/tag/string.md) `1+` | 🟠 | [🀄️](https://leetcode.cn/problems/verify-preorder-serialization-of-a-binary-tree) [🔗](https://leetcode.com/problems/verify-preorder-serialization-of-a-binary-tree) | | 334 | 递增的三元子序列 | [[✓]](/problem/0334.md) | [`贪心`](/tag/greedy.md) [`数组`](/tag/array.md) | 🟠 | [🀄️](https://leetcode.cn/problems/increasing-triplet-subsequence) [🔗](https://leetcode.com/problems/increasing-triplet-subsequence) | +| 337 | 打家劫舍 III | [[✓]](/problem/0337.md) | [`树`](/tag/tree.md) [`深度优先搜索`](/tag/depth-first-search.md) [`动态规划`](/tag/dynamic-programming.md) `1+` | 🟠 | [🀄️](https://leetcode.cn/problems/house-robber-iii) [🔗](https://leetcode.com/problems/house-robber-iii) | | 338 | 比特位计数 | [[✓]](/problem/0338.md) | [`位运算`](/tag/bit-manipulation.md) [`动态规划`](/tag/dynamic-programming.md) | 🟢 | [🀄️](https://leetcode.cn/problems/counting-bits) [🔗](https://leetcode.com/problems/counting-bits) | +| 341 | 扁平化嵌套列表迭代器 | [[✓]](/problem/0341.md) | [`栈`](/tag/stack.md) [`树`](/tag/tree.md) [`深度优先搜索`](/tag/depth-first-search.md) `3+` | 🟠 | [🀄️](https://leetcode.cn/problems/flatten-nested-list-iterator) [🔗](https://leetcode.com/problems/flatten-nested-list-iterator) | | 342 | 4的幂 | [[✓]](/problem/0342.md) | [`位运算`](/tag/bit-manipulation.md) [`递归`](/tag/recursion.md) [`数学`](/tag/math.md) | 🟢 | [🀄️](https://leetcode.cn/problems/power-of-four) [🔗](https://leetcode.com/problems/power-of-four) | | 343 | 整数拆分 | [[✓]](/problem/0343.md) | [`数学`](/tag/math.md) [`动态规划`](/tag/dynamic-programming.md) | 🟠 | [🀄️](https://leetcode.cn/problems/integer-break) [🔗](https://leetcode.com/problems/integer-break) | | 344 | 反转字符串 | [[✓]](/problem/0344.md) | [`双指针`](/tag/two-pointers.md) [`字符串`](/tag/string.md) | 🟢 | [🀄️](https://leetcode.cn/problems/reverse-string) [🔗](https://leetcode.com/problems/reverse-string) | @@ -265,6 +273,7 @@ | 350 | 两个数组的交集 II | [[✓]](/problem/0350.md) | [`数组`](/tag/array.md) [`哈希表`](/tag/hash-table.md) [`双指针`](/tag/two-pointers.md) `2+` | 🟢 | [🀄️](https://leetcode.cn/problems/intersection-of-two-arrays-ii) [🔗](https://leetcode.com/problems/intersection-of-two-arrays-ii) | | 354 | 俄罗斯套娃信封问题 | [[✓]](/problem/0354.md) | [`数组`](/tag/array.md) [`二分查找`](/tag/binary-search.md) [`动态规划`](/tag/dynamic-programming.md) `1+` | 🔴 | [🀄️](https://leetcode.cn/problems/russian-doll-envelopes) [🔗](https://leetcode.com/problems/russian-doll-envelopes) | | 355 | 设计推特 | [[✓]](/problem/0355.md) | [`设计`](/tag/design.md) [`哈希表`](/tag/hash-table.md) [`链表`](/tag/linked-list.md) `1+` | 🟠 | [🀄️](https://leetcode.cn/problems/design-twitter) [🔗](https://leetcode.com/problems/design-twitter) | +| 357 | 统计各位数字都不同的数字个数 | [[✓]](/problem/0357.md) | [`数学`](/tag/math.md) [`动态规划`](/tag/dynamic-programming.md) [`回溯`](/tag/backtracking.md) | 🟠 | [🀄️](https://leetcode.cn/problems/count-numbers-with-unique-digits) [🔗](https://leetcode.com/problems/count-numbers-with-unique-digits) | | 366 | 寻找二叉树的叶子节点 🔒 | [[✓]](/problem/0366.md) | [`树`](/tag/tree.md) [`深度优先搜索`](/tag/depth-first-search.md) [`二叉树`](/tag/binary-tree.md) | 🟠 | [🀄️](https://leetcode.cn/problems/find-leaves-of-binary-tree) [🔗](https://leetcode.com/problems/find-leaves-of-binary-tree) | | 367 | 有效的完全平方数 | [[✓]](/problem/0367.md) | [`数学`](/tag/math.md) [`二分查找`](/tag/binary-search.md) | 🟢 | [🀄️](https://leetcode.cn/problems/valid-perfect-square) [🔗](https://leetcode.com/problems/valid-perfect-square) | | 369 | 给单链表加一 🔒 | [[✓]](/problem/0369.md) | [`链表`](/tag/linked-list.md) [`数学`](/tag/math.md) | 🟠 | [🀄️](https://leetcode.cn/problems/plus-one-linked-list) [🔗](https://leetcode.com/problems/plus-one-linked-list) | @@ -285,6 +294,7 @@ | 401 | 二进制手表 | [[✓]](/problem/0401.md) | [`位运算`](/tag/bit-manipulation.md) [`回溯`](/tag/backtracking.md) | 🟢 | [🀄️](https://leetcode.cn/problems/binary-watch) [🔗](https://leetcode.com/problems/binary-watch) | | 404 | 左叶子之和 | [[✓]](/problem/0404.md) | [`树`](/tag/tree.md) [`深度优先搜索`](/tag/depth-first-search.md) [`广度优先搜索`](/tag/breadth-first-search.md) `1+` | 🟢 | [🀄️](https://leetcode.cn/problems/sum-of-left-leaves) [🔗](https://leetcode.com/problems/sum-of-left-leaves) | | 405 | 数字转换为十六进制数 | [[✓]](/problem/0405.md) | [`位运算`](/tag/bit-manipulation.md) [`数学`](/tag/math.md) | 🟢 | [🀄️](https://leetcode.cn/problems/convert-a-number-to-hexadecimal) [🔗](https://leetcode.com/problems/convert-a-number-to-hexadecimal) | +| 407 | 接雨水 II | [[✓]](/problem/0407.md) | [`广度优先搜索`](/tag/breadth-first-search.md) [`数组`](/tag/array.md) [`矩阵`](/tag/matrix.md) `1+` | 🔴 | [🀄️](https://leetcode.cn/problems/trapping-rain-water-ii) [🔗](https://leetcode.com/problems/trapping-rain-water-ii) | | 409 | 最长回文串 | [[✓]](/problem/0409.md) | [`贪心`](/tag/greedy.md) [`哈希表`](/tag/hash-table.md) [`字符串`](/tag/string.md) | 🟢 | [🀄️](https://leetcode.cn/problems/longest-palindrome) [🔗](https://leetcode.com/problems/longest-palindrome) | | 412 | Fizz Buzz | [[✓]](/problem/0412.md) | [`数学`](/tag/math.md) [`字符串`](/tag/string.md) [`模拟`](/tag/simulation.md) | 🟢 | [🀄️](https://leetcode.cn/problems/fizz-buzz) [🔗](https://leetcode.com/problems/fizz-buzz) | | 414 | 第三大的数 | [[✓]](/problem/0414.md) | [`数组`](/tag/array.md) [`排序`](/tag/sorting.md) | 🟢 | [🀄️](https://leetcode.cn/problems/third-maximum-number) [🔗](https://leetcode.com/problems/third-maximum-number) | @@ -539,6 +549,7 @@ | 1252 | 奇数值单元格的数目 | [[✓]](/problem/1252.md) | [`数组`](/tag/array.md) [`数学`](/tag/math.md) [`模拟`](/tag/simulation.md) | 🟢 | [🀄️](https://leetcode.cn/problems/cells-with-odd-values-in-a-matrix) [🔗](https://leetcode.com/problems/cells-with-odd-values-in-a-matrix) | | 1260 | 二维网格迁移 | [[✓]](/problem/1260.md) | [`数组`](/tag/array.md) [`矩阵`](/tag/matrix.md) [`模拟`](/tag/simulation.md) | 🟢 | [🀄️](https://leetcode.cn/problems/shift-2d-grid) [🔗](https://leetcode.com/problems/shift-2d-grid) | | 1266 | 访问所有点的最小时间 | [[✓]](/problem/1266.md) | [`几何`](/tag/geometry.md) [`数组`](/tag/array.md) [`数学`](/tag/math.md) | 🟢 | [🀄️](https://leetcode.cn/problems/minimum-time-visiting-all-points) [🔗](https://leetcode.com/problems/minimum-time-visiting-all-points) | +| 1267 | 统计参与通信的服务器 | [[✓]](/problem/1267.md) | [`深度优先搜索`](/tag/depth-first-search.md) [`广度优先搜索`](/tag/breadth-first-search.md) [`并查集`](/tag/union-find.md) `3+` | 🟠 | [🀄️](https://leetcode.cn/problems/count-servers-that-communicate) [🔗](https://leetcode.com/problems/count-servers-that-communicate) | | 1268 | 搜索推荐系统 | [[✓]](/problem/1268.md) | [`字典树`](/tag/trie.md) [`数组`](/tag/array.md) [`字符串`](/tag/string.md) `3+` | 🟠 | [🀄️](https://leetcode.cn/problems/search-suggestions-system) [🔗](https://leetcode.com/problems/search-suggestions-system) | | 1275 | 找出井字棋的获胜者 | [[✓]](/problem/1275.md) | [`数组`](/tag/array.md) [`哈希表`](/tag/hash-table.md) [`矩阵`](/tag/matrix.md) `1+` | 🟢 | [🀄️](https://leetcode.cn/problems/find-winner-on-a-tic-tac-toe-game) [🔗](https://leetcode.com/problems/find-winner-on-a-tic-tac-toe-game) | | 1277 | 统计全为 1 的正方形子矩阵 | [[✓]](/problem/1277.md) | [`数组`](/tag/array.md) [`动态规划`](/tag/dynamic-programming.md) [`矩阵`](/tag/matrix.md) | 🟠 | [🀄️](https://leetcode.cn/problems/count-square-submatrices-with-all-ones) [🔗](https://leetcode.com/problems/count-square-submatrices-with-all-ones) | @@ -672,6 +683,7 @@ | 1758 | 生成交替二进制字符串的最少操作数 | [[✓]](/problem/1758.md) | [`字符串`](/tag/string.md) | 🟢 | [🀄️](https://leetcode.cn/problems/minimum-changes-to-make-alternating-binary-string) [🔗](https://leetcode.com/problems/minimum-changes-to-make-alternating-binary-string) | | 1760 | 袋子里最少数目的球 | [[✓]](/problem/1760.md) | [`数组`](/tag/array.md) [`二分查找`](/tag/binary-search.md) | 🟠 | [🀄️](https://leetcode.cn/problems/minimum-limit-of-balls-in-a-bag) [🔗](https://leetcode.com/problems/minimum-limit-of-balls-in-a-bag) | | 1763 | 最长的美好子字符串 | [[✓]](/problem/1763.md) | [`位运算`](/tag/bit-manipulation.md) [`哈希表`](/tag/hash-table.md) [`字符串`](/tag/string.md) `2+` | 🟢 | [🀄️](https://leetcode.cn/problems/longest-nice-substring) [🔗](https://leetcode.com/problems/longest-nice-substring) | +| 1765 | 地图中的最高点 | [[✓]](/problem/1765.md) | [`广度优先搜索`](/tag/breadth-first-search.md) [`数组`](/tag/array.md) [`矩阵`](/tag/matrix.md) | 🟠 | [🀄️](https://leetcode.cn/problems/map-of-highest-peak) [🔗](https://leetcode.com/problems/map-of-highest-peak) | | 1768 | 交替合并字符串 | [[✓]](/problem/1768.md) | [`双指针`](/tag/two-pointers.md) [`字符串`](/tag/string.md) | 🟢 | [🀄️](https://leetcode.cn/problems/merge-strings-alternately) [🔗](https://leetcode.com/problems/merge-strings-alternately) | | 1769 | 移动所有球到每个盒子所需的最小操作数 | [[✓]](/problem/1769.md) | [`数组`](/tag/array.md) [`字符串`](/tag/string.md) [`前缀和`](/tag/prefix-sum.md) | 🟠 | [🀄️](https://leetcode.cn/problems/minimum-number-of-operations-to-move-all-balls-to-each-box) [🔗](https://leetcode.com/problems/minimum-number-of-operations-to-move-all-balls-to-each-box) | | 1773 | 统计匹配检索规则的物品数量 | [[✓]](/problem/1773.md) | [`数组`](/tag/array.md) [`字符串`](/tag/string.md) | 🟢 | [🀄️](https://leetcode.cn/problems/count-items-matching-a-rule) [🔗](https://leetcode.com/problems/count-items-matching-a-rule) | @@ -732,6 +744,7 @@ | 2006 | 差的绝对值为 K 的数对数目 | [[✓]](/problem/2006.md) | [`数组`](/tag/array.md) [`哈希表`](/tag/hash-table.md) [`计数`](/tag/counting.md) | 🟢 | [🀄️](https://leetcode.cn/problems/count-number-of-pairs-with-absolute-difference-k) [🔗](https://leetcode.com/problems/count-number-of-pairs-with-absolute-difference-k) | | 2011 | 执行操作后的变量值 | [[✓]](/problem/2011.md) | [`数组`](/tag/array.md) [`字符串`](/tag/string.md) [`模拟`](/tag/simulation.md) | 🟢 | [🀄️](https://leetcode.cn/problems/final-value-of-variable-after-performing-operations) [🔗](https://leetcode.com/problems/final-value-of-variable-after-performing-operations) | | 2016 | 增量元素之间的最大差值 | [[✓]](/problem/2016.md) | [`数组`](/tag/array.md) | 🟢 | [🀄️](https://leetcode.cn/problems/maximum-difference-between-increasing-elements) [🔗](https://leetcode.com/problems/maximum-difference-between-increasing-elements) | +| 2017 | 网格游戏 | [[✓]](/problem/2017.md) | [`数组`](/tag/array.md) [`矩阵`](/tag/matrix.md) [`前缀和`](/tag/prefix-sum.md) | 🟠 | [🀄️](https://leetcode.cn/problems/grid-game) [🔗](https://leetcode.com/problems/grid-game) | | 2022 | 将一维数组转变成二维数组 | [[✓]](/problem/2022.md) | [`数组`](/tag/array.md) [`矩阵`](/tag/matrix.md) [`模拟`](/tag/simulation.md) | 🟢 | [🀄️](https://leetcode.cn/problems/convert-1d-array-into-2d-array) [🔗](https://leetcode.com/problems/convert-1d-array-into-2d-array) | | 2027 | 转换字符串的最少操作次数 | [[✓]](/problem/2027.md) | [`贪心`](/tag/greedy.md) [`字符串`](/tag/string.md) | 🟢 | [🀄️](https://leetcode.cn/problems/minimum-moves-to-convert-string) [🔗](https://leetcode.com/problems/minimum-moves-to-convert-string) | | 2032 | 至少在两个数组中出现的值 | [[✓]](/problem/2032.md) | [`位运算`](/tag/bit-manipulation.md) [`数组`](/tag/array.md) [`哈希表`](/tag/hash-table.md) | 🟢 | [🀄️](https://leetcode.cn/problems/two-out-of-three) [🔗](https://leetcode.com/problems/two-out-of-three) | @@ -881,12 +894,14 @@ | 2649 | 嵌套数组生成器 | [[✓]](/problem/2649.md) | | 🟠 | [🀄️](https://leetcode.cn/problems/nested-array-generator) [🔗](https://leetcode.com/problems/nested-array-generator) | | 2650 | 设计可取消函数 | [[✓]](/problem/2650.md) | | 🔴 | [🀄️](https://leetcode.cn/problems/design-cancellable-function) [🔗](https://leetcode.com/problems/design-cancellable-function) | | 2657 | 找到两个数组的前缀公共数组 | [[✓]](/problem/2657.md) | [`位运算`](/tag/bit-manipulation.md) [`数组`](/tag/array.md) [`哈希表`](/tag/hash-table.md) | 🟠 | [🀄️](https://leetcode.cn/problems/find-the-prefix-common-array-of-two-arrays) [🔗](https://leetcode.com/problems/find-the-prefix-common-array-of-two-arrays) | +| 2661 | 找出叠涂元素 | [[✓]](/problem/2661.md) | [`数组`](/tag/array.md) [`哈希表`](/tag/hash-table.md) [`矩阵`](/tag/matrix.md) | 🟠 | [🀄️](https://leetcode.cn/problems/first-completely-painted-row-or-column) [🔗](https://leetcode.com/problems/first-completely-painted-row-or-column) | | 2665 | 计数器 II | [[✓]](/problem/2665.md) | | 🟢 | [🀄️](https://leetcode.cn/problems/counter-ii) [🔗](https://leetcode.com/problems/counter-ii) | | 2666 | 只允许一次函数调用 | [[✓]](/problem/2666.md) | | 🟢 | [🀄️](https://leetcode.cn/problems/allow-one-function-call) [🔗](https://leetcode.com/problems/allow-one-function-call) | | 2667 | 创建 Hello World 函数 | [[✓]](/problem/2667.md) | | 🟢 | [🀄️](https://leetcode.cn/problems/create-hello-world-function) [🔗](https://leetcode.com/problems/create-hello-world-function) | | 2675 | 将对象数组转换为矩阵 🔒 | [[✓]](/problem/2675.md) | | 🔴 | [🀄️](https://leetcode.cn/problems/array-of-objects-to-matrix) [🔗](https://leetcode.com/problems/array-of-objects-to-matrix) | | 2676 | 节流 🔒 | [[✓]](/problem/2676.md) | | 🟠 | [🀄️](https://leetcode.cn/problems/throttle) [🔗](https://leetcode.com/problems/throttle) | | 2677 | 分块数组 | [[✓]](/problem/2677.md) | | 🟢 | [🀄️](https://leetcode.cn/problems/chunk-array) [🔗](https://leetcode.com/problems/chunk-array) | +| 2683 | 相邻值的按位异或 | [[✓]](/problem/2683.md) | [`位运算`](/tag/bit-manipulation.md) [`数组`](/tag/array.md) | 🟠 | [🀄️](https://leetcode.cn/problems/neighboring-bitwise-xor) [🔗](https://leetcode.com/problems/neighboring-bitwise-xor) | | 2684 | 矩阵中移动的最大次数 | [[✓]](/problem/2684.md) | [`数组`](/tag/array.md) [`动态规划`](/tag/dynamic-programming.md) [`矩阵`](/tag/matrix.md) | 🟠 | [🀄️](https://leetcode.cn/problems/maximum-number-of-moves-in-a-grid) [🔗](https://leetcode.com/problems/maximum-number-of-moves-in-a-grid) | | 2690 | 无穷方法对象 🔒 | [[✓]](/problem/2690.md) | | 🟢 | [🀄️](https://leetcode.cn/problems/infinite-method-object) [🔗](https://leetcode.com/problems/infinite-method-object) | | 2691 | 不可变辅助工具 🔒 | [[✓]](/problem/2691.md) | | 🔴 | [🀄️](https://leetcode.cn/problems/immutability-helper) [🔗](https://leetcode.com/problems/immutability-helper) | diff --git a/src/tag/array.md b/src/tag/array.md index 05ed7d5f27..e5c469ba90 100644 --- a/src/tag/array.md +++ b/src/tag/array.md @@ -155,10 +155,10 @@ | 309 | 买卖股票的最佳时机含冷冻期 | [[✓]](/problem/0309.md) | [`数组`](/tag/array.md) [`动态规划`](/tag/dynamic-programming.md) | 🟠 | [🀄️](https://leetcode.cn/problems/best-time-to-buy-and-sell-stock-with-cooldown) [🔗](https://leetcode.com/problems/best-time-to-buy-and-sell-stock-with-cooldown) | | 311 | 稀疏矩阵的乘法 🔒 | | [`数组`](/tag/array.md) [`哈希表`](/tag/hash-table.md) [`矩阵`](/tag/matrix.md) | 🟠 | [🀄️](https://leetcode.cn/problems/sparse-matrix-multiplication) [🔗](https://leetcode.com/problems/sparse-matrix-multiplication) | | 312 | 戳气球 | | [`数组`](/tag/array.md) [`动态规划`](/tag/dynamic-programming.md) | 🔴 | [🀄️](https://leetcode.cn/problems/burst-balloons) [🔗](https://leetcode.com/problems/burst-balloons) | -| 313 | 超级丑数 | | [`数组`](/tag/array.md) [`数学`](/tag/math.md) [`动态规划`](/tag/dynamic-programming.md) | 🟠 | [🀄️](https://leetcode.cn/problems/super-ugly-number) [🔗](https://leetcode.com/problems/super-ugly-number) | +| 313 | 超级丑数 | [[✓]](/problem/0313.md) | [`数组`](/tag/array.md) [`数学`](/tag/math.md) [`动态规划`](/tag/dynamic-programming.md) | 🟠 | [🀄️](https://leetcode.cn/problems/super-ugly-number) [🔗](https://leetcode.com/problems/super-ugly-number) | | 315 | 计算右侧小于当前元素的个数 | | [`树状数组`](/tag/binary-indexed-tree.md) [`线段树`](/tag/segment-tree.md) [`数组`](/tag/array.md) `4+` | 🔴 | [🀄️](https://leetcode.cn/problems/count-of-smaller-numbers-after-self) [🔗](https://leetcode.com/problems/count-of-smaller-numbers-after-self) | | 317 | 离建筑物最近的距离 🔒 | | [`广度优先搜索`](/tag/breadth-first-search.md) [`数组`](/tag/array.md) [`矩阵`](/tag/matrix.md) | 🔴 | [🀄️](https://leetcode.cn/problems/shortest-distance-from-all-buildings) [🔗](https://leetcode.com/problems/shortest-distance-from-all-buildings) | -| 318 | 最大单词长度乘积 | | [`位运算`](/tag/bit-manipulation.md) [`数组`](/tag/array.md) [`字符串`](/tag/string.md) | 🟠 | [🀄️](https://leetcode.cn/problems/maximum-product-of-word-lengths) [🔗](https://leetcode.com/problems/maximum-product-of-word-lengths) | +| 318 | 最大单词长度乘积 | [[✓]](/problem/0318.md) | [`位运算`](/tag/bit-manipulation.md) [`数组`](/tag/array.md) [`字符串`](/tag/string.md) | 🟠 | [🀄️](https://leetcode.cn/problems/maximum-product-of-word-lengths) [🔗](https://leetcode.com/problems/maximum-product-of-word-lengths) | | 321 | 拼接最大数 | | [`栈`](/tag/stack.md) [`贪心`](/tag/greedy.md) [`数组`](/tag/array.md) `2+` | 🔴 | [🀄️](https://leetcode.cn/problems/create-maximum-number) [🔗](https://leetcode.com/problems/create-maximum-number) | | 322 | 零钱兑换 | [[✓]](/problem/0322.md) | [`广度优先搜索`](/tag/breadth-first-search.md) [`数组`](/tag/array.md) [`动态规划`](/tag/dynamic-programming.md) | 🟠 | [🀄️](https://leetcode.cn/problems/coin-change) [🔗](https://leetcode.com/problems/coin-change) | | 324 | 摆动排序 II | | [`贪心`](/tag/greedy.md) [`数组`](/tag/array.md) [`分治`](/tag/divide-and-conquer.md) `2+` | 🟠 | [🀄️](https://leetcode.cn/problems/wiggle-sort-ii) [🔗](https://leetcode.com/problems/wiggle-sort-ii) | @@ -197,7 +197,7 @@ | 399 | 除法求值 | [[✓]](/problem/0399.md) | [`深度优先搜索`](/tag/depth-first-search.md) [`广度优先搜索`](/tag/breadth-first-search.md) [`并查集`](/tag/union-find.md) `4+` | 🟠 | [🀄️](https://leetcode.cn/problems/evaluate-division) [🔗](https://leetcode.com/problems/evaluate-division) | | 403 | 青蛙过河 | | [`数组`](/tag/array.md) [`动态规划`](/tag/dynamic-programming.md) | 🔴 | [🀄️](https://leetcode.cn/problems/frog-jump) [🔗](https://leetcode.com/problems/frog-jump) | | 406 | 根据身高重建队列 | | [`树状数组`](/tag/binary-indexed-tree.md) [`线段树`](/tag/segment-tree.md) [`数组`](/tag/array.md) `1+` | 🟠 | [🀄️](https://leetcode.cn/problems/queue-reconstruction-by-height) [🔗](https://leetcode.com/problems/queue-reconstruction-by-height) | -| 407 | 接雨水 II | | [`广度优先搜索`](/tag/breadth-first-search.md) [`数组`](/tag/array.md) [`矩阵`](/tag/matrix.md) `1+` | 🔴 | [🀄️](https://leetcode.cn/problems/trapping-rain-water-ii) [🔗](https://leetcode.com/problems/trapping-rain-water-ii) | +| 407 | 接雨水 II | [[✓]](/problem/0407.md) | [`广度优先搜索`](/tag/breadth-first-search.md) [`数组`](/tag/array.md) [`矩阵`](/tag/matrix.md) `1+` | 🔴 | [🀄️](https://leetcode.cn/problems/trapping-rain-water-ii) [🔗](https://leetcode.com/problems/trapping-rain-water-ii) | | 410 | 分割数组的最大值 | | [`贪心`](/tag/greedy.md) [`数组`](/tag/array.md) [`二分查找`](/tag/binary-search.md) `2+` | 🔴 | [🀄️](https://leetcode.cn/problems/split-array-largest-sum) [🔗](https://leetcode.com/problems/split-array-largest-sum) | | 411 | 最短独占单词缩写 🔒 | | [`位运算`](/tag/bit-manipulation.md) [`数组`](/tag/array.md) [`字符串`](/tag/string.md) `1+` | 🔴 | [🀄️](https://leetcode.cn/problems/minimum-unique-word-abbreviation) [🔗](https://leetcode.com/problems/minimum-unique-word-abbreviation) | | 413 | 等差数列划分 | | [`数组`](/tag/array.md) [`动态规划`](/tag/dynamic-programming.md) [`滑动窗口`](/tag/sliding-window.md) | 🟠 | [🀄️](https://leetcode.cn/problems/arithmetic-slices) [🔗](https://leetcode.com/problems/arithmetic-slices) | diff --git a/src/tag/backtracking.md b/src/tag/backtracking.md index 4f4b32f321..84e86660f2 100644 --- a/src/tag/backtracking.md +++ b/src/tag/backtracking.md @@ -49,10 +49,10 @@ | 291 | 单词规律 II 🔒 | | [`哈希表`](/tag/hash-table.md) [`字符串`](/tag/string.md) [`回溯`](/tag/backtracking.md) | 🟠 | [🀄️](https://leetcode.cn/problems/word-pattern-ii) [🔗](https://leetcode.com/problems/word-pattern-ii) | | 294 | 翻转游戏 II 🔒 | | [`记忆化搜索`](/tag/memoization.md) [`数学`](/tag/math.md) [`动态规划`](/tag/dynamic-programming.md) `2+` | 🟠 | [🀄️](https://leetcode.cn/problems/flip-game-ii) [🔗](https://leetcode.com/problems/flip-game-ii) | | 301 | 删除无效的括号 | | [`广度优先搜索`](/tag/breadth-first-search.md) [`字符串`](/tag/string.md) [`回溯`](/tag/backtracking.md) | 🔴 | [🀄️](https://leetcode.cn/problems/remove-invalid-parentheses) [🔗](https://leetcode.com/problems/remove-invalid-parentheses) | -| 306 | 累加数 | | [`字符串`](/tag/string.md) [`回溯`](/tag/backtracking.md) | 🟠 | [🀄️](https://leetcode.cn/problems/additive-number) [🔗](https://leetcode.com/problems/additive-number) | +| 306 | 累加数 | [[✓]](/problem/0306.md) | [`字符串`](/tag/string.md) [`回溯`](/tag/backtracking.md) | 🟠 | [🀄️](https://leetcode.cn/problems/additive-number) [🔗](https://leetcode.com/problems/additive-number) | | 320 | 列举单词的全部缩写 🔒 | | [`位运算`](/tag/bit-manipulation.md) [`字符串`](/tag/string.md) [`回溯`](/tag/backtracking.md) | 🟠 | [🀄️](https://leetcode.cn/problems/generalized-abbreviation) [🔗](https://leetcode.com/problems/generalized-abbreviation) | | 351 | 安卓系统手势解锁 🔒 | | [`位运算`](/tag/bit-manipulation.md) [`动态规划`](/tag/dynamic-programming.md) [`回溯`](/tag/backtracking.md) `1+` | 🟠 | [🀄️](https://leetcode.cn/problems/android-unlock-patterns) [🔗](https://leetcode.com/problems/android-unlock-patterns) | -| 357 | 统计各位数字都不同的数字个数 | | [`数学`](/tag/math.md) [`动态规划`](/tag/dynamic-programming.md) [`回溯`](/tag/backtracking.md) | 🟠 | [🀄️](https://leetcode.cn/problems/count-numbers-with-unique-digits) [🔗](https://leetcode.com/problems/count-numbers-with-unique-digits) | +| 357 | 统计各位数字都不同的数字个数 | [[✓]](/problem/0357.md) | [`数学`](/tag/math.md) [`动态规划`](/tag/dynamic-programming.md) [`回溯`](/tag/backtracking.md) | 🟠 | [🀄️](https://leetcode.cn/problems/count-numbers-with-unique-digits) [🔗](https://leetcode.com/problems/count-numbers-with-unique-digits) | | 401 | 二进制手表 | [[✓]](/problem/0401.md) | [`位运算`](/tag/bit-manipulation.md) [`回溯`](/tag/backtracking.md) | 🟢 | [🀄️](https://leetcode.cn/problems/binary-watch) [🔗](https://leetcode.com/problems/binary-watch) | | 411 | 最短独占单词缩写 🔒 | | [`位运算`](/tag/bit-manipulation.md) [`数组`](/tag/array.md) [`字符串`](/tag/string.md) `1+` | 🔴 | [🀄️](https://leetcode.cn/problems/minimum-unique-word-abbreviation) [🔗](https://leetcode.com/problems/minimum-unique-word-abbreviation) | | 425 | 单词方块 🔒 | | [`字典树`](/tag/trie.md) [`数组`](/tag/array.md) [`字符串`](/tag/string.md) `1+` | 🔴 | [🀄️](https://leetcode.cn/problems/word-squares) [🔗](https://leetcode.com/problems/word-squares) | diff --git a/src/tag/binary-tree.md b/src/tag/binary-tree.md index 506c5729b8..6bfc1f7eaf 100644 --- a/src/tag/binary-tree.md +++ b/src/tag/binary-tree.md @@ -63,9 +63,9 @@ | 297 | 二叉树的序列化与反序列化 | [[✓]](/problem/0297.md) | [`树`](/tag/tree.md) [`深度优先搜索`](/tag/depth-first-search.md) [`广度优先搜索`](/tag/breadth-first-search.md) `3+` | 🔴 | [🀄️](https://leetcode.cn/problems/serialize-and-deserialize-binary-tree) [🔗](https://leetcode.com/problems/serialize-and-deserialize-binary-tree) | | 298 | 二叉树最长连续序列 🔒 | | [`树`](/tag/tree.md) [`深度优先搜索`](/tag/depth-first-search.md) [`二叉树`](/tag/binary-tree.md) | 🟠 | [🀄️](https://leetcode.cn/problems/binary-tree-longest-consecutive-sequence) [🔗](https://leetcode.com/problems/binary-tree-longest-consecutive-sequence) | | 314 | 二叉树的垂直遍历 🔒 | | [`树`](/tag/tree.md) [`深度优先搜索`](/tag/depth-first-search.md) [`广度优先搜索`](/tag/breadth-first-search.md) `3+` | 🟠 | [🀄️](https://leetcode.cn/problems/binary-tree-vertical-order-traversal) [🔗](https://leetcode.com/problems/binary-tree-vertical-order-traversal) | -| 331 | 验证二叉树的前序序列化 | | [`栈`](/tag/stack.md) [`树`](/tag/tree.md) [`字符串`](/tag/string.md) `1+` | 🟠 | [🀄️](https://leetcode.cn/problems/verify-preorder-serialization-of-a-binary-tree) [🔗](https://leetcode.com/problems/verify-preorder-serialization-of-a-binary-tree) | +| 331 | 验证二叉树的前序序列化 | [[✓]](/problem/0331.md) | [`栈`](/tag/stack.md) [`树`](/tag/tree.md) [`字符串`](/tag/string.md) `1+` | 🟠 | [🀄️](https://leetcode.cn/problems/verify-preorder-serialization-of-a-binary-tree) [🔗](https://leetcode.com/problems/verify-preorder-serialization-of-a-binary-tree) | | 333 | 最大二叉搜索子树 🔒 | | [`树`](/tag/tree.md) [`深度优先搜索`](/tag/depth-first-search.md) [`二叉搜索树`](/tag/binary-search-tree.md) `2+` | 🟠 | [🀄️](https://leetcode.cn/problems/largest-bst-subtree) [🔗](https://leetcode.com/problems/largest-bst-subtree) | -| 337 | 打家劫舍 III | | [`树`](/tag/tree.md) [`深度优先搜索`](/tag/depth-first-search.md) [`动态规划`](/tag/dynamic-programming.md) `1+` | 🟠 | [🀄️](https://leetcode.cn/problems/house-robber-iii) [🔗](https://leetcode.com/problems/house-robber-iii) | +| 337 | 打家劫舍 III | [[✓]](/problem/0337.md) | [`树`](/tag/tree.md) [`深度优先搜索`](/tag/depth-first-search.md) [`动态规划`](/tag/dynamic-programming.md) `1+` | 🟠 | [🀄️](https://leetcode.cn/problems/house-robber-iii) [🔗](https://leetcode.com/problems/house-robber-iii) | | 366 | 寻找二叉树的叶子节点 🔒 | [[✓]](/problem/0366.md) | [`树`](/tag/tree.md) [`深度优先搜索`](/tag/depth-first-search.md) [`二叉树`](/tag/binary-tree.md) | 🟠 | [🀄️](https://leetcode.cn/problems/find-leaves-of-binary-tree) [🔗](https://leetcode.com/problems/find-leaves-of-binary-tree) | | 404 | 左叶子之和 | [[✓]](/problem/0404.md) | [`树`](/tag/tree.md) [`深度优先搜索`](/tag/depth-first-search.md) [`广度优先搜索`](/tag/breadth-first-search.md) `1+` | 🟢 | [🀄️](https://leetcode.cn/problems/sum-of-left-leaves) [🔗](https://leetcode.com/problems/sum-of-left-leaves) | | 426 | 将二叉搜索树转化为排序的双向链表 🔒 | [[✓]](/problem/0426.md) | [`栈`](/tag/stack.md) [`树`](/tag/tree.md) [`深度优先搜索`](/tag/depth-first-search.md) `4+` | 🟠 | [🀄️](https://leetcode.cn/problems/convert-binary-search-tree-to-sorted-doubly-linked-list) [🔗](https://leetcode.com/problems/convert-binary-search-tree-to-sorted-doubly-linked-list) | diff --git a/src/tag/bit-manipulation.md b/src/tag/bit-manipulation.md index 47f4629f4d..a75d3de20c 100644 --- a/src/tag/bit-manipulation.md +++ b/src/tag/bit-manipulation.md @@ -37,7 +37,7 @@ | 266 | 回文排列 🔒 | | [`位运算`](/tag/bit-manipulation.md) [`哈希表`](/tag/hash-table.md) [`字符串`](/tag/string.md) | 🟢 | [🀄️](https://leetcode.cn/problems/palindrome-permutation) [🔗](https://leetcode.com/problems/palindrome-permutation) | | 268 | 丢失的数字 | [[✓]](/problem/0268.md) | [`位运算`](/tag/bit-manipulation.md) [`数组`](/tag/array.md) [`哈希表`](/tag/hash-table.md) `3+` | 🟢 | [🀄️](https://leetcode.cn/problems/missing-number) [🔗](https://leetcode.com/problems/missing-number) | | 287 | 寻找重复数 | [[✓]](/problem/0287.md) | [`位运算`](/tag/bit-manipulation.md) [`数组`](/tag/array.md) [`双指针`](/tag/two-pointers.md) `1+` | 🟠 | [🀄️](https://leetcode.cn/problems/find-the-duplicate-number) [🔗](https://leetcode.com/problems/find-the-duplicate-number) | -| 318 | 最大单词长度乘积 | | [`位运算`](/tag/bit-manipulation.md) [`数组`](/tag/array.md) [`字符串`](/tag/string.md) | 🟠 | [🀄️](https://leetcode.cn/problems/maximum-product-of-word-lengths) [🔗](https://leetcode.com/problems/maximum-product-of-word-lengths) | +| 318 | 最大单词长度乘积 | [[✓]](/problem/0318.md) | [`位运算`](/tag/bit-manipulation.md) [`数组`](/tag/array.md) [`字符串`](/tag/string.md) | 🟠 | [🀄️](https://leetcode.cn/problems/maximum-product-of-word-lengths) [🔗](https://leetcode.com/problems/maximum-product-of-word-lengths) | | 320 | 列举单词的全部缩写 🔒 | | [`位运算`](/tag/bit-manipulation.md) [`字符串`](/tag/string.md) [`回溯`](/tag/backtracking.md) | 🟠 | [🀄️](https://leetcode.cn/problems/generalized-abbreviation) [🔗](https://leetcode.com/problems/generalized-abbreviation) | | 338 | 比特位计数 | [[✓]](/problem/0338.md) | [`位运算`](/tag/bit-manipulation.md) [`动态规划`](/tag/dynamic-programming.md) | 🟢 | [🀄️](https://leetcode.cn/problems/counting-bits) [🔗](https://leetcode.com/problems/counting-bits) | | 342 | 4的幂 | [[✓]](/problem/0342.md) | [`位运算`](/tag/bit-manipulation.md) [`递归`](/tag/recursion.md) [`数学`](/tag/math.md) | 🟢 | [🀄️](https://leetcode.cn/problems/power-of-four) [🔗](https://leetcode.com/problems/power-of-four) | @@ -189,7 +189,7 @@ | 2595 | 奇偶位数 | | [`位运算`](/tag/bit-manipulation.md) | 🟢 | [🀄️](https://leetcode.cn/problems/number-of-even-and-odd-bits) [🔗](https://leetcode.com/problems/number-of-even-and-odd-bits) | | 2657 | 找到两个数组的前缀公共数组 | [[✓]](/problem/2657.md) | [`位运算`](/tag/bit-manipulation.md) [`数组`](/tag/array.md) [`哈希表`](/tag/hash-table.md) | 🟠 | [🀄️](https://leetcode.cn/problems/find-the-prefix-common-array-of-two-arrays) [🔗](https://leetcode.com/problems/find-the-prefix-common-array-of-two-arrays) | | 2680 | 最大或值 | | [`贪心`](/tag/greedy.md) [`位运算`](/tag/bit-manipulation.md) [`数组`](/tag/array.md) `1+` | 🟠 | [🀄️](https://leetcode.cn/problems/maximum-or) [🔗](https://leetcode.com/problems/maximum-or) | -| 2683 | 相邻值的按位异或 | | [`位运算`](/tag/bit-manipulation.md) [`数组`](/tag/array.md) | 🟠 | [🀄️](https://leetcode.cn/problems/neighboring-bitwise-xor) [🔗](https://leetcode.com/problems/neighboring-bitwise-xor) | +| 2683 | 相邻值的按位异或 | [[✓]](/problem/2683.md) | [`位运算`](/tag/bit-manipulation.md) [`数组`](/tag/array.md) | 🟠 | [🀄️](https://leetcode.cn/problems/neighboring-bitwise-xor) [🔗](https://leetcode.com/problems/neighboring-bitwise-xor) | | 2708 | 一个小组的最大实力值 | | [`贪心`](/tag/greedy.md) [`位运算`](/tag/bit-manipulation.md) [`数组`](/tag/array.md) `4+` | 🟠 | [🀄️](https://leetcode.cn/problems/maximum-strength-of-a-group) [🔗](https://leetcode.com/problems/maximum-strength-of-a-group) | | 2732 | 找到矩阵中的好子集 | | [`位运算`](/tag/bit-manipulation.md) [`数组`](/tag/array.md) [`哈希表`](/tag/hash-table.md) `1+` | 🔴 | [🀄️](https://leetcode.cn/problems/find-a-good-subset-of-the-matrix) [🔗](https://leetcode.com/problems/find-a-good-subset-of-the-matrix) | | 2741 | 特别的排列 | | [`位运算`](/tag/bit-manipulation.md) [`数组`](/tag/array.md) [`动态规划`](/tag/dynamic-programming.md) `1+` | 🟠 | [🀄️](https://leetcode.cn/problems/special-permutations) [🔗](https://leetcode.com/problems/special-permutations) | diff --git a/src/tag/brainteaser.md b/src/tag/brainteaser.md index ee3f6e7f76..7a0057f049 100644 --- a/src/tag/brainteaser.md +++ b/src/tag/brainteaser.md @@ -21,7 +21,7 @@ | 题号 | 标题 | 题解 | 标签 | 难度 | 力扣 | | :------: | :------ | :------: | :------ | :------: | :------: | | 292 | Nim 游戏 | [[✓]](/problem/0292.md) | [`脑筋急转弯`](/tag/brainteaser.md) [`数学`](/tag/math.md) [`博弈`](/tag/game-theory.md) | 🟢 | [🀄️](https://leetcode.cn/problems/nim-game) [🔗](https://leetcode.com/problems/nim-game) | -| 319 | 灯泡开关 | | [`脑筋急转弯`](/tag/brainteaser.md) [`数学`](/tag/math.md) | 🟠 | [🀄️](https://leetcode.cn/problems/bulb-switcher) [🔗](https://leetcode.com/problems/bulb-switcher) | +| 319 | 灯泡开关 | [[✓]](/problem/0319.md) | [`脑筋急转弯`](/tag/brainteaser.md) [`数学`](/tag/math.md) | 🟠 | [🀄️](https://leetcode.cn/problems/bulb-switcher) [🔗](https://leetcode.com/problems/bulb-switcher) | | 810 | 黑板异或游戏 | | [`位运算`](/tag/bit-manipulation.md) [`脑筋急转弯`](/tag/brainteaser.md) [`数组`](/tag/array.md) `2+` | 🔴 | [🀄️](https://leetcode.cn/problems/chalkboard-xor-game) [🔗](https://leetcode.com/problems/chalkboard-xor-game) | | 1025 | 除数博弈 | [[✓]](/problem/1025.md) | [`脑筋急转弯`](/tag/brainteaser.md) [`数学`](/tag/math.md) [`动态规划`](/tag/dynamic-programming.md) `1+` | 🟢 | [🀄️](https://leetcode.cn/problems/divisor-game) [🔗](https://leetcode.com/problems/divisor-game) | | 1033 | 移动石子直到连续 | | [`脑筋急转弯`](/tag/brainteaser.md) [`数学`](/tag/math.md) | 🟠 | [🀄️](https://leetcode.cn/problems/moving-stones-until-consecutive) [🔗](https://leetcode.com/problems/moving-stones-until-consecutive) | diff --git a/src/tag/breadth-first-search.md b/src/tag/breadth-first-search.md index d5e79ebbe5..f922e28487 100644 --- a/src/tag/breadth-first-search.md +++ b/src/tag/breadth-first-search.md @@ -46,7 +46,7 @@ | 297 | 二叉树的序列化与反序列化 | [[✓]](/problem/0297.md) | [`树`](/tag/tree.md) [`深度优先搜索`](/tag/depth-first-search.md) [`广度优先搜索`](/tag/breadth-first-search.md) `3+` | 🔴 | [🀄️](https://leetcode.cn/problems/serialize-and-deserialize-binary-tree) [🔗](https://leetcode.com/problems/serialize-and-deserialize-binary-tree) | | 301 | 删除无效的括号 | | [`广度优先搜索`](/tag/breadth-first-search.md) [`字符串`](/tag/string.md) [`回溯`](/tag/backtracking.md) | 🔴 | [🀄️](https://leetcode.cn/problems/remove-invalid-parentheses) [🔗](https://leetcode.com/problems/remove-invalid-parentheses) | | 302 | 包含全部黑色像素的最小矩形 🔒 | | [`深度优先搜索`](/tag/depth-first-search.md) [`广度优先搜索`](/tag/breadth-first-search.md) [`数组`](/tag/array.md) `2+` | 🔴 | [🀄️](https://leetcode.cn/problems/smallest-rectangle-enclosing-black-pixels) [🔗](https://leetcode.com/problems/smallest-rectangle-enclosing-black-pixels) | -| 310 | 最小高度树 | | [`深度优先搜索`](/tag/depth-first-search.md) [`广度优先搜索`](/tag/breadth-first-search.md) [`图`](/tag/graph.md) `1+` | 🟠 | [🀄️](https://leetcode.cn/problems/minimum-height-trees) [🔗](https://leetcode.com/problems/minimum-height-trees) | +| 310 | 最小高度树 | [[✓]](/problem/0310.md) | [`深度优先搜索`](/tag/depth-first-search.md) [`广度优先搜索`](/tag/breadth-first-search.md) [`图`](/tag/graph.md) `1+` | 🟠 | [🀄️](https://leetcode.cn/problems/minimum-height-trees) [🔗](https://leetcode.com/problems/minimum-height-trees) | | 314 | 二叉树的垂直遍历 🔒 | | [`树`](/tag/tree.md) [`深度优先搜索`](/tag/depth-first-search.md) [`广度优先搜索`](/tag/breadth-first-search.md) `3+` | 🟠 | [🀄️](https://leetcode.cn/problems/binary-tree-vertical-order-traversal) [🔗](https://leetcode.com/problems/binary-tree-vertical-order-traversal) | | 317 | 离建筑物最近的距离 🔒 | | [`广度优先搜索`](/tag/breadth-first-search.md) [`数组`](/tag/array.md) [`矩阵`](/tag/matrix.md) | 🔴 | [🀄️](https://leetcode.cn/problems/shortest-distance-from-all-buildings) [🔗](https://leetcode.com/problems/shortest-distance-from-all-buildings) | | 322 | 零钱兑换 | [[✓]](/problem/0322.md) | [`广度优先搜索`](/tag/breadth-first-search.md) [`数组`](/tag/array.md) [`动态规划`](/tag/dynamic-programming.md) | 🟠 | [🀄️](https://leetcode.cn/problems/coin-change) [🔗](https://leetcode.com/problems/coin-change) | @@ -57,7 +57,7 @@ | 365 | 水壶问题 | | [`深度优先搜索`](/tag/depth-first-search.md) [`广度优先搜索`](/tag/breadth-first-search.md) [`数学`](/tag/math.md) | 🟠 | [🀄️](https://leetcode.cn/problems/water-and-jug-problem) [🔗](https://leetcode.com/problems/water-and-jug-problem) | | 399 | 除法求值 | [[✓]](/problem/0399.md) | [`深度优先搜索`](/tag/depth-first-search.md) [`广度优先搜索`](/tag/breadth-first-search.md) [`并查集`](/tag/union-find.md) `4+` | 🟠 | [🀄️](https://leetcode.cn/problems/evaluate-division) [🔗](https://leetcode.com/problems/evaluate-division) | | 404 | 左叶子之和 | [[✓]](/problem/0404.md) | [`树`](/tag/tree.md) [`深度优先搜索`](/tag/depth-first-search.md) [`广度优先搜索`](/tag/breadth-first-search.md) `1+` | 🟢 | [🀄️](https://leetcode.cn/problems/sum-of-left-leaves) [🔗](https://leetcode.com/problems/sum-of-left-leaves) | -| 407 | 接雨水 II | | [`广度优先搜索`](/tag/breadth-first-search.md) [`数组`](/tag/array.md) [`矩阵`](/tag/matrix.md) `1+` | 🔴 | [🀄️](https://leetcode.cn/problems/trapping-rain-water-ii) [🔗](https://leetcode.com/problems/trapping-rain-water-ii) | +| 407 | 接雨水 II | [[✓]](/problem/0407.md) | [`广度优先搜索`](/tag/breadth-first-search.md) [`数组`](/tag/array.md) [`矩阵`](/tag/matrix.md) `1+` | 🔴 | [🀄️](https://leetcode.cn/problems/trapping-rain-water-ii) [🔗](https://leetcode.com/problems/trapping-rain-water-ii) | | 417 | 太平洋大西洋水流问题 | | [`深度优先搜索`](/tag/depth-first-search.md) [`广度优先搜索`](/tag/breadth-first-search.md) [`数组`](/tag/array.md) `1+` | 🟠 | [🀄️](https://leetcode.cn/problems/pacific-atlantic-water-flow) [🔗](https://leetcode.com/problems/pacific-atlantic-water-flow) | | 428 | 序列化和反序列化 N 叉树 🔒 | | [`树`](/tag/tree.md) [`深度优先搜索`](/tag/depth-first-search.md) [`广度优先搜索`](/tag/breadth-first-search.md) `1+` | 🔴 | [🀄️](https://leetcode.cn/problems/serialize-and-deserialize-n-ary-tree) [🔗](https://leetcode.com/problems/serialize-and-deserialize-n-ary-tree) | | 429 | N 叉树的层序遍历 | | [`树`](/tag/tree.md) [`广度优先搜索`](/tag/breadth-first-search.md) | 🟠 | [🀄️](https://leetcode.cn/problems/n-ary-tree-level-order-traversal) [🔗](https://leetcode.com/problems/n-ary-tree-level-order-traversal) | @@ -154,7 +154,7 @@ | 1257 | 最小公共区域 🔒 | | [`树`](/tag/tree.md) [`深度优先搜索`](/tag/depth-first-search.md) [`广度优先搜索`](/tag/breadth-first-search.md) `3+` | 🟠 | [🀄️](https://leetcode.cn/problems/smallest-common-region) [🔗](https://leetcode.com/problems/smallest-common-region) | | 1261 | 在受污染的二叉树中查找元素 | | [`树`](/tag/tree.md) [`深度优先搜索`](/tag/depth-first-search.md) [`广度优先搜索`](/tag/breadth-first-search.md) `3+` | 🟠 | [🀄️](https://leetcode.cn/problems/find-elements-in-a-contaminated-binary-tree) [🔗](https://leetcode.com/problems/find-elements-in-a-contaminated-binary-tree) | | 1263 | 推箱子 | | [`广度优先搜索`](/tag/breadth-first-search.md) [`数组`](/tag/array.md) [`矩阵`](/tag/matrix.md) `1+` | 🔴 | [🀄️](https://leetcode.cn/problems/minimum-moves-to-move-a-box-to-their-target-location) [🔗](https://leetcode.com/problems/minimum-moves-to-move-a-box-to-their-target-location) | -| 1267 | 统计参与通信的服务器 | | [`深度优先搜索`](/tag/depth-first-search.md) [`广度优先搜索`](/tag/breadth-first-search.md) [`并查集`](/tag/union-find.md) `3+` | 🟠 | [🀄️](https://leetcode.cn/problems/count-servers-that-communicate) [🔗](https://leetcode.com/problems/count-servers-that-communicate) | +| 1267 | 统计参与通信的服务器 | [[✓]](/problem/1267.md) | [`深度优先搜索`](/tag/depth-first-search.md) [`广度优先搜索`](/tag/breadth-first-search.md) [`并查集`](/tag/union-find.md) `3+` | 🟠 | [🀄️](https://leetcode.cn/problems/count-servers-that-communicate) [🔗](https://leetcode.com/problems/count-servers-that-communicate) | | 1273 | 删除树节点 🔒 | | [`树`](/tag/tree.md) [`深度优先搜索`](/tag/depth-first-search.md) [`广度优先搜索`](/tag/breadth-first-search.md) `1+` | 🟠 | [🀄️](https://leetcode.cn/problems/delete-tree-nodes) [🔗](https://leetcode.com/problems/delete-tree-nodes) | | 1284 | 转化为全零矩阵的最少反转次数 | | [`位运算`](/tag/bit-manipulation.md) [`广度优先搜索`](/tag/breadth-first-search.md) [`数组`](/tag/array.md) `2+` | 🔴 | [🀄️](https://leetcode.cn/problems/minimum-number-of-flips-to-convert-binary-matrix-to-zero-matrix) [🔗](https://leetcode.com/problems/minimum-number-of-flips-to-convert-binary-matrix-to-zero-matrix) | | 1293 | 网格中的最短路径 | | [`广度优先搜索`](/tag/breadth-first-search.md) [`数组`](/tag/array.md) [`矩阵`](/tag/matrix.md) | 🔴 | [🀄️](https://leetcode.cn/problems/shortest-path-in-a-grid-with-obstacles-elimination) [🔗](https://leetcode.com/problems/shortest-path-in-a-grid-with-obstacles-elimination) | @@ -192,7 +192,7 @@ | 1660 | 纠正二叉树 🔒 | | [`树`](/tag/tree.md) [`深度优先搜索`](/tag/depth-first-search.md) [`广度优先搜索`](/tag/breadth-first-search.md) `2+` | 🟠 | [🀄️](https://leetcode.cn/problems/correct-a-binary-tree) [🔗](https://leetcode.com/problems/correct-a-binary-tree) | | 1730 | 获取食物的最短路径 🔒 | | [`广度优先搜索`](/tag/breadth-first-search.md) [`数组`](/tag/array.md) [`矩阵`](/tag/matrix.md) | 🟠 | [🀄️](https://leetcode.cn/problems/shortest-path-to-get-food) [🔗](https://leetcode.com/problems/shortest-path-to-get-food) | | 1740 | 找到二叉树中的距离 🔒 | | [`树`](/tag/tree.md) [`深度优先搜索`](/tag/depth-first-search.md) [`广度优先搜索`](/tag/breadth-first-search.md) `2+` | 🟠 | [🀄️](https://leetcode.cn/problems/find-distance-in-a-binary-tree) [🔗](https://leetcode.com/problems/find-distance-in-a-binary-tree) | -| 1765 | 地图中的最高点 | | [`广度优先搜索`](/tag/breadth-first-search.md) [`数组`](/tag/array.md) [`矩阵`](/tag/matrix.md) | 🟠 | [🀄️](https://leetcode.cn/problems/map-of-highest-peak) [🔗](https://leetcode.com/problems/map-of-highest-peak) | +| 1765 | 地图中的最高点 | [[✓]](/problem/1765.md) | [`广度优先搜索`](/tag/breadth-first-search.md) [`数组`](/tag/array.md) [`矩阵`](/tag/matrix.md) | 🟠 | [🀄️](https://leetcode.cn/problems/map-of-highest-peak) [🔗](https://leetcode.com/problems/map-of-highest-peak) | | 1778 | 未知网格中的最短路径 🔒 | | [`深度优先搜索`](/tag/depth-first-search.md) [`广度优先搜索`](/tag/breadth-first-search.md) [`图`](/tag/graph.md) `1+` | 🟠 | [🀄️](https://leetcode.cn/problems/shortest-path-in-a-hidden-grid) [🔗](https://leetcode.com/problems/shortest-path-in-a-hidden-grid) | | 1810 | 隐藏网格下的最小消耗路径 🔒 | | [`深度优先搜索`](/tag/depth-first-search.md) [`广度优先搜索`](/tag/breadth-first-search.md) [`图`](/tag/graph.md) `2+` | 🟠 | [🀄️](https://leetcode.cn/problems/minimum-path-cost-in-a-hidden-grid) [🔗](https://leetcode.com/problems/minimum-path-cost-in-a-hidden-grid) | | 1905 | 统计子岛屿 | | [`深度优先搜索`](/tag/depth-first-search.md) [`广度优先搜索`](/tag/breadth-first-search.md) [`并查集`](/tag/union-find.md) `2+` | 🟠 | [🀄️](https://leetcode.cn/problems/count-sub-islands) [🔗](https://leetcode.com/problems/count-sub-islands) | diff --git a/src/tag/counting.md b/src/tag/counting.md index e28aba069a..57aa6e28c1 100644 --- a/src/tag/counting.md +++ b/src/tag/counting.md @@ -52,7 +52,7 @@ | 1198 | 找出所有行中最小公共元素 🔒 | | [`数组`](/tag/array.md) [`哈希表`](/tag/hash-table.md) [`二分查找`](/tag/binary-search.md) `2+` | 🟠 | [🀄️](https://leetcode.cn/problems/find-smallest-common-element-in-all-rows) [🔗](https://leetcode.com/problems/find-smallest-common-element-in-all-rows) | | 1213 | 三个有序数组的交集 🔒 | | [`数组`](/tag/array.md) [`哈希表`](/tag/hash-table.md) [`二分查找`](/tag/binary-search.md) `1+` | 🟢 | [🀄️](https://leetcode.cn/problems/intersection-of-three-sorted-arrays) [🔗](https://leetcode.com/problems/intersection-of-three-sorted-arrays) | | 1221 | 分割平衡字符串 | [[✓]](/problem/1221.md) | [`贪心`](/tag/greedy.md) [`字符串`](/tag/string.md) [`计数`](/tag/counting.md) | 🟢 | [🀄️](https://leetcode.cn/problems/split-a-string-in-balanced-strings) [🔗](https://leetcode.com/problems/split-a-string-in-balanced-strings) | -| 1267 | 统计参与通信的服务器 | | [`深度优先搜索`](/tag/depth-first-search.md) [`广度优先搜索`](/tag/breadth-first-search.md) [`并查集`](/tag/union-find.md) `3+` | 🟠 | [🀄️](https://leetcode.cn/problems/count-servers-that-communicate) [🔗](https://leetcode.com/problems/count-servers-that-communicate) | +| 1267 | 统计参与通信的服务器 | [[✓]](/problem/1267.md) | [`深度优先搜索`](/tag/depth-first-search.md) [`广度优先搜索`](/tag/breadth-first-search.md) [`并查集`](/tag/union-find.md) `3+` | 🟠 | [🀄️](https://leetcode.cn/problems/count-servers-that-communicate) [🔗](https://leetcode.com/problems/count-servers-that-communicate) | | 1347 | 制造字母异位词的最小步骤数 | | [`哈希表`](/tag/hash-table.md) [`字符串`](/tag/string.md) [`计数`](/tag/counting.md) | 🟠 | [🀄️](https://leetcode.cn/problems/minimum-number-of-steps-to-make-two-strings-anagram) [🔗](https://leetcode.com/problems/minimum-number-of-steps-to-make-two-strings-anagram) | | 1356 | 根据数字二进制下 1 的数目排序 | [[✓]](/problem/1356.md) | [`位运算`](/tag/bit-manipulation.md) [`数组`](/tag/array.md) [`计数`](/tag/counting.md) `1+` | 🟢 | [🀄️](https://leetcode.cn/problems/sort-integers-by-the-number-of-1-bits) [🔗](https://leetcode.com/problems/sort-integers-by-the-number-of-1-bits) | | 1365 | 有多少小于当前数字的数字 | [[✓]](/problem/1365.md) | [`数组`](/tag/array.md) [`哈希表`](/tag/hash-table.md) [`计数`](/tag/counting.md) `1+` | 🟢 | [🀄️](https://leetcode.cn/problems/how-many-numbers-are-smaller-than-the-current-number) [🔗](https://leetcode.com/problems/how-many-numbers-are-smaller-than-the-current-number) | diff --git a/src/tag/depth-first-search.md b/src/tag/depth-first-search.md index 8446effd9b..10e889f268 100644 --- a/src/tag/depth-first-search.md +++ b/src/tag/depth-first-search.md @@ -59,15 +59,15 @@ | 297 | 二叉树的序列化与反序列化 | [[✓]](/problem/0297.md) | [`树`](/tag/tree.md) [`深度优先搜索`](/tag/depth-first-search.md) [`广度优先搜索`](/tag/breadth-first-search.md) `3+` | 🔴 | [🀄️](https://leetcode.cn/problems/serialize-and-deserialize-binary-tree) [🔗](https://leetcode.com/problems/serialize-and-deserialize-binary-tree) | | 298 | 二叉树最长连续序列 🔒 | | [`树`](/tag/tree.md) [`深度优先搜索`](/tag/depth-first-search.md) [`二叉树`](/tag/binary-tree.md) | 🟠 | [🀄️](https://leetcode.cn/problems/binary-tree-longest-consecutive-sequence) [🔗](https://leetcode.com/problems/binary-tree-longest-consecutive-sequence) | | 302 | 包含全部黑色像素的最小矩形 🔒 | | [`深度优先搜索`](/tag/depth-first-search.md) [`广度优先搜索`](/tag/breadth-first-search.md) [`数组`](/tag/array.md) `2+` | 🔴 | [🀄️](https://leetcode.cn/problems/smallest-rectangle-enclosing-black-pixels) [🔗](https://leetcode.com/problems/smallest-rectangle-enclosing-black-pixels) | -| 310 | 最小高度树 | | [`深度优先搜索`](/tag/depth-first-search.md) [`广度优先搜索`](/tag/breadth-first-search.md) [`图`](/tag/graph.md) `1+` | 🟠 | [🀄️](https://leetcode.cn/problems/minimum-height-trees) [🔗](https://leetcode.com/problems/minimum-height-trees) | +| 310 | 最小高度树 | [[✓]](/problem/0310.md) | [`深度优先搜索`](/tag/depth-first-search.md) [`广度优先搜索`](/tag/breadth-first-search.md) [`图`](/tag/graph.md) `1+` | 🟠 | [🀄️](https://leetcode.cn/problems/minimum-height-trees) [🔗](https://leetcode.com/problems/minimum-height-trees) | | 314 | 二叉树的垂直遍历 🔒 | | [`树`](/tag/tree.md) [`深度优先搜索`](/tag/depth-first-search.md) [`广度优先搜索`](/tag/breadth-first-search.md) `3+` | 🟠 | [🀄️](https://leetcode.cn/problems/binary-tree-vertical-order-traversal) [🔗](https://leetcode.com/problems/binary-tree-vertical-order-traversal) | | 323 | 无向图中连通分量的数目 🔒 | | [`深度优先搜索`](/tag/depth-first-search.md) [`广度优先搜索`](/tag/breadth-first-search.md) [`并查集`](/tag/union-find.md) `1+` | 🟠 | [🀄️](https://leetcode.cn/problems/number-of-connected-components-in-an-undirected-graph) [🔗](https://leetcode.com/problems/number-of-connected-components-in-an-undirected-graph) | | 329 | 矩阵中的最长递增路径 | | [`深度优先搜索`](/tag/depth-first-search.md) [`广度优先搜索`](/tag/breadth-first-search.md) [`图`](/tag/graph.md) `5+` | 🔴 | [🀄️](https://leetcode.cn/problems/longest-increasing-path-in-a-matrix) [🔗](https://leetcode.com/problems/longest-increasing-path-in-a-matrix) | | 332 | 重新安排行程 | | [`深度优先搜索`](/tag/depth-first-search.md) [`图`](/tag/graph.md) [`欧拉回路`](/tag/eulerian-circuit.md) | 🔴 | [🀄️](https://leetcode.cn/problems/reconstruct-itinerary) [🔗](https://leetcode.com/problems/reconstruct-itinerary) | | 333 | 最大二叉搜索子树 🔒 | | [`树`](/tag/tree.md) [`深度优先搜索`](/tag/depth-first-search.md) [`二叉搜索树`](/tag/binary-search-tree.md) `2+` | 🟠 | [🀄️](https://leetcode.cn/problems/largest-bst-subtree) [🔗](https://leetcode.com/problems/largest-bst-subtree) | -| 337 | 打家劫舍 III | | [`树`](/tag/tree.md) [`深度优先搜索`](/tag/depth-first-search.md) [`动态规划`](/tag/dynamic-programming.md) `1+` | 🟠 | [🀄️](https://leetcode.cn/problems/house-robber-iii) [🔗](https://leetcode.com/problems/house-robber-iii) | +| 337 | 打家劫舍 III | [[✓]](/problem/0337.md) | [`树`](/tag/tree.md) [`深度优先搜索`](/tag/depth-first-search.md) [`动态规划`](/tag/dynamic-programming.md) `1+` | 🟠 | [🀄️](https://leetcode.cn/problems/house-robber-iii) [🔗](https://leetcode.com/problems/house-robber-iii) | | 339 | 嵌套列表加权和 🔒 | | [`深度优先搜索`](/tag/depth-first-search.md) [`广度优先搜索`](/tag/breadth-first-search.md) | 🟠 | [🀄️](https://leetcode.cn/problems/nested-list-weight-sum) [🔗](https://leetcode.com/problems/nested-list-weight-sum) | -| 341 | 扁平化嵌套列表迭代器 | | [`栈`](/tag/stack.md) [`树`](/tag/tree.md) [`深度优先搜索`](/tag/depth-first-search.md) `3+` | 🟠 | [🀄️](https://leetcode.cn/problems/flatten-nested-list-iterator) [🔗](https://leetcode.com/problems/flatten-nested-list-iterator) | +| 341 | 扁平化嵌套列表迭代器 | [[✓]](/problem/0341.md) | [`栈`](/tag/stack.md) [`树`](/tag/tree.md) [`深度优先搜索`](/tag/depth-first-search.md) `3+` | 🟠 | [🀄️](https://leetcode.cn/problems/flatten-nested-list-iterator) [🔗](https://leetcode.com/problems/flatten-nested-list-iterator) | | 364 | 嵌套列表加权和 II 🔒 | | [`栈`](/tag/stack.md) [`深度优先搜索`](/tag/depth-first-search.md) [`广度优先搜索`](/tag/breadth-first-search.md) | 🟠 | [🀄️](https://leetcode.cn/problems/nested-list-weight-sum-ii) [🔗](https://leetcode.com/problems/nested-list-weight-sum-ii) | | 365 | 水壶问题 | | [`深度优先搜索`](/tag/depth-first-search.md) [`广度优先搜索`](/tag/breadth-first-search.md) [`数学`](/tag/math.md) | 🟠 | [🀄️](https://leetcode.cn/problems/water-and-jug-problem) [🔗](https://leetcode.com/problems/water-and-jug-problem) | | 366 | 寻找二叉树的叶子节点 🔒 | [[✓]](/problem/0366.md) | [`树`](/tag/tree.md) [`深度优先搜索`](/tag/depth-first-search.md) [`二叉树`](/tag/binary-tree.md) | 🟠 | [🀄️](https://leetcode.cn/problems/find-leaves-of-binary-tree) [🔗](https://leetcode.com/problems/find-leaves-of-binary-tree) | @@ -197,7 +197,7 @@ | 1254 | 统计封闭岛屿的数目 | | [`深度优先搜索`](/tag/depth-first-search.md) [`广度优先搜索`](/tag/breadth-first-search.md) [`并查集`](/tag/union-find.md) `2+` | 🟠 | [🀄️](https://leetcode.cn/problems/number-of-closed-islands) [🔗](https://leetcode.com/problems/number-of-closed-islands) | | 1257 | 最小公共区域 🔒 | | [`树`](/tag/tree.md) [`深度优先搜索`](/tag/depth-first-search.md) [`广度优先搜索`](/tag/breadth-first-search.md) `3+` | 🟠 | [🀄️](https://leetcode.cn/problems/smallest-common-region) [🔗](https://leetcode.com/problems/smallest-common-region) | | 1261 | 在受污染的二叉树中查找元素 | | [`树`](/tag/tree.md) [`深度优先搜索`](/tag/depth-first-search.md) [`广度优先搜索`](/tag/breadth-first-search.md) `3+` | 🟠 | [🀄️](https://leetcode.cn/problems/find-elements-in-a-contaminated-binary-tree) [🔗](https://leetcode.com/problems/find-elements-in-a-contaminated-binary-tree) | -| 1267 | 统计参与通信的服务器 | | [`深度优先搜索`](/tag/depth-first-search.md) [`广度优先搜索`](/tag/breadth-first-search.md) [`并查集`](/tag/union-find.md) `3+` | 🟠 | [🀄️](https://leetcode.cn/problems/count-servers-that-communicate) [🔗](https://leetcode.com/problems/count-servers-that-communicate) | +| 1267 | 统计参与通信的服务器 | [[✓]](/problem/1267.md) | [`深度优先搜索`](/tag/depth-first-search.md) [`广度优先搜索`](/tag/breadth-first-search.md) [`并查集`](/tag/union-find.md) `3+` | 🟠 | [🀄️](https://leetcode.cn/problems/count-servers-that-communicate) [🔗](https://leetcode.com/problems/count-servers-that-communicate) | | 1273 | 删除树节点 🔒 | | [`树`](/tag/tree.md) [`深度优先搜索`](/tag/depth-first-search.md) [`广度优先搜索`](/tag/breadth-first-search.md) `1+` | 🟠 | [🀄️](https://leetcode.cn/problems/delete-tree-nodes) [🔗](https://leetcode.com/problems/delete-tree-nodes) | | 1302 | 层数最深叶子节点的和 | | [`树`](/tag/tree.md) [`深度优先搜索`](/tag/depth-first-search.md) [`广度优先搜索`](/tag/breadth-first-search.md) `1+` | 🟠 | [🀄️](https://leetcode.cn/problems/deepest-leaves-sum) [🔗](https://leetcode.com/problems/deepest-leaves-sum) | | 1305 | 两棵二叉搜索树中的所有元素 | | [`树`](/tag/tree.md) [`深度优先搜索`](/tag/depth-first-search.md) [`二叉搜索树`](/tag/binary-search-tree.md) `2+` | 🟠 | [🀄️](https://leetcode.cn/problems/all-elements-in-two-binary-search-trees) [🔗](https://leetcode.com/problems/all-elements-in-two-binary-search-trees) | diff --git a/src/tag/design.md b/src/tag/design.md index e55a59e4ca..69ade2371e 100644 --- a/src/tag/design.md +++ b/src/tag/design.md @@ -40,7 +40,7 @@ | 304 | 二维区域和检索 - 矩阵不可变 | [[✓]](/problem/0304.md) | [`设计`](/tag/design.md) [`数组`](/tag/array.md) [`矩阵`](/tag/matrix.md) `1+` | 🟠 | [🀄️](https://leetcode.cn/problems/range-sum-query-2d-immutable) [🔗](https://leetcode.com/problems/range-sum-query-2d-immutable) | | 307 | 区域和检索 - 数组可修改 | [[✓]](/problem/0307.md) | [`设计`](/tag/design.md) [`树状数组`](/tag/binary-indexed-tree.md) [`线段树`](/tag/segment-tree.md) `1+` | 🟠 | [🀄️](https://leetcode.cn/problems/range-sum-query-mutable) [🔗](https://leetcode.com/problems/range-sum-query-mutable) | | 308 | 二维区域和检索 - 矩阵可修改 🔒 | | [`设计`](/tag/design.md) [`树状数组`](/tag/binary-indexed-tree.md) [`线段树`](/tag/segment-tree.md) `2+` | 🔴 | [🀄️](https://leetcode.cn/problems/range-sum-query-2d-mutable) [🔗](https://leetcode.com/problems/range-sum-query-2d-mutable) | -| 341 | 扁平化嵌套列表迭代器 | | [`栈`](/tag/stack.md) [`树`](/tag/tree.md) [`深度优先搜索`](/tag/depth-first-search.md) `3+` | 🟠 | [🀄️](https://leetcode.cn/problems/flatten-nested-list-iterator) [🔗](https://leetcode.com/problems/flatten-nested-list-iterator) | +| 341 | 扁平化嵌套列表迭代器 | [[✓]](/problem/0341.md) | [`栈`](/tag/stack.md) [`树`](/tag/tree.md) [`深度优先搜索`](/tag/depth-first-search.md) `3+` | 🟠 | [🀄️](https://leetcode.cn/problems/flatten-nested-list-iterator) [🔗](https://leetcode.com/problems/flatten-nested-list-iterator) | | 346 | 数据流中的移动平均值 🔒 | [[✓]](/problem/0346.md) | [`设计`](/tag/design.md) [`队列`](/tag/queue.md) [`数组`](/tag/array.md) `1+` | 🟢 | [🀄️](https://leetcode.cn/problems/moving-average-from-data-stream) [🔗](https://leetcode.com/problems/moving-average-from-data-stream) | | 348 | 设计井字棋 🔒 | | [`设计`](/tag/design.md) [`数组`](/tag/array.md) [`哈希表`](/tag/hash-table.md) `2+` | 🟠 | [🀄️](https://leetcode.cn/problems/design-tic-tac-toe) [🔗](https://leetcode.com/problems/design-tic-tac-toe) | | 352 | 将数据流变为多个不相交区间 | | [`设计`](/tag/design.md) [`二分查找`](/tag/binary-search.md) [`有序集合`](/tag/ordered-set.md) | 🔴 | [🀄️](https://leetcode.cn/problems/data-stream-as-disjoint-intervals) [🔗](https://leetcode.com/problems/data-stream-as-disjoint-intervals) | diff --git a/src/tag/dynamic-programming.md b/src/tag/dynamic-programming.md index 3080a5451b..b817326d91 100644 --- a/src/tag/dynamic-programming.md +++ b/src/tag/dynamic-programming.md @@ -69,16 +69,16 @@ | 300 | 最长递增子序列 | [[✓]](/problem/0300.md) | [`数组`](/tag/array.md) [`二分查找`](/tag/binary-search.md) [`动态规划`](/tag/dynamic-programming.md) | 🟠 | [🀄️](https://leetcode.cn/problems/longest-increasing-subsequence) [🔗](https://leetcode.com/problems/longest-increasing-subsequence) | | 309 | 买卖股票的最佳时机含冷冻期 | [[✓]](/problem/0309.md) | [`数组`](/tag/array.md) [`动态规划`](/tag/dynamic-programming.md) | 🟠 | [🀄️](https://leetcode.cn/problems/best-time-to-buy-and-sell-stock-with-cooldown) [🔗](https://leetcode.com/problems/best-time-to-buy-and-sell-stock-with-cooldown) | | 312 | 戳气球 | | [`数组`](/tag/array.md) [`动态规划`](/tag/dynamic-programming.md) | 🔴 | [🀄️](https://leetcode.cn/problems/burst-balloons) [🔗](https://leetcode.com/problems/burst-balloons) | -| 313 | 超级丑数 | | [`数组`](/tag/array.md) [`数学`](/tag/math.md) [`动态规划`](/tag/dynamic-programming.md) | 🟠 | [🀄️](https://leetcode.cn/problems/super-ugly-number) [🔗](https://leetcode.com/problems/super-ugly-number) | +| 313 | 超级丑数 | [[✓]](/problem/0313.md) | [`数组`](/tag/array.md) [`数学`](/tag/math.md) [`动态规划`](/tag/dynamic-programming.md) | 🟠 | [🀄️](https://leetcode.cn/problems/super-ugly-number) [🔗](https://leetcode.com/problems/super-ugly-number) | | 322 | 零钱兑换 | [[✓]](/problem/0322.md) | [`广度优先搜索`](/tag/breadth-first-search.md) [`数组`](/tag/array.md) [`动态规划`](/tag/dynamic-programming.md) | 🟠 | [🀄️](https://leetcode.cn/problems/coin-change) [🔗](https://leetcode.com/problems/coin-change) | | 329 | 矩阵中的最长递增路径 | | [`深度优先搜索`](/tag/depth-first-search.md) [`广度优先搜索`](/tag/breadth-first-search.md) [`图`](/tag/graph.md) `5+` | 🔴 | [🀄️](https://leetcode.cn/problems/longest-increasing-path-in-a-matrix) [🔗](https://leetcode.com/problems/longest-increasing-path-in-a-matrix) | | 333 | 最大二叉搜索子树 🔒 | | [`树`](/tag/tree.md) [`深度优先搜索`](/tag/depth-first-search.md) [`二叉搜索树`](/tag/binary-search-tree.md) `2+` | 🟠 | [🀄️](https://leetcode.cn/problems/largest-bst-subtree) [🔗](https://leetcode.com/problems/largest-bst-subtree) | -| 337 | 打家劫舍 III | | [`树`](/tag/tree.md) [`深度优先搜索`](/tag/depth-first-search.md) [`动态规划`](/tag/dynamic-programming.md) `1+` | 🟠 | [🀄️](https://leetcode.cn/problems/house-robber-iii) [🔗](https://leetcode.com/problems/house-robber-iii) | +| 337 | 打家劫舍 III | [[✓]](/problem/0337.md) | [`树`](/tag/tree.md) [`深度优先搜索`](/tag/depth-first-search.md) [`动态规划`](/tag/dynamic-programming.md) `1+` | 🟠 | [🀄️](https://leetcode.cn/problems/house-robber-iii) [🔗](https://leetcode.com/problems/house-robber-iii) | | 338 | 比特位计数 | [[✓]](/problem/0338.md) | [`位运算`](/tag/bit-manipulation.md) [`动态规划`](/tag/dynamic-programming.md) | 🟢 | [🀄️](https://leetcode.cn/problems/counting-bits) [🔗](https://leetcode.com/problems/counting-bits) | | 343 | 整数拆分 | [[✓]](/problem/0343.md) | [`数学`](/tag/math.md) [`动态规划`](/tag/dynamic-programming.md) | 🟠 | [🀄️](https://leetcode.cn/problems/integer-break) [🔗](https://leetcode.com/problems/integer-break) | | 351 | 安卓系统手势解锁 🔒 | | [`位运算`](/tag/bit-manipulation.md) [`动态规划`](/tag/dynamic-programming.md) [`回溯`](/tag/backtracking.md) `1+` | 🟠 | [🀄️](https://leetcode.cn/problems/android-unlock-patterns) [🔗](https://leetcode.com/problems/android-unlock-patterns) | | 354 | 俄罗斯套娃信封问题 | [[✓]](/problem/0354.md) | [`数组`](/tag/array.md) [`二分查找`](/tag/binary-search.md) [`动态规划`](/tag/dynamic-programming.md) `1+` | 🔴 | [🀄️](https://leetcode.cn/problems/russian-doll-envelopes) [🔗](https://leetcode.com/problems/russian-doll-envelopes) | -| 357 | 统计各位数字都不同的数字个数 | | [`数学`](/tag/math.md) [`动态规划`](/tag/dynamic-programming.md) [`回溯`](/tag/backtracking.md) | 🟠 | [🀄️](https://leetcode.cn/problems/count-numbers-with-unique-digits) [🔗](https://leetcode.com/problems/count-numbers-with-unique-digits) | +| 357 | 统计各位数字都不同的数字个数 | [[✓]](/problem/0357.md) | [`数学`](/tag/math.md) [`动态规划`](/tag/dynamic-programming.md) [`回溯`](/tag/backtracking.md) | 🟠 | [🀄️](https://leetcode.cn/problems/count-numbers-with-unique-digits) [🔗](https://leetcode.com/problems/count-numbers-with-unique-digits) | | 361 | 轰炸敌人 🔒 | | [`数组`](/tag/array.md) [`动态规划`](/tag/dynamic-programming.md) [`矩阵`](/tag/matrix.md) | 🟠 | [🀄️](https://leetcode.cn/problems/bomb-enemy) [🔗](https://leetcode.com/problems/bomb-enemy) | | 368 | 最大整除子集 | | [`数组`](/tag/array.md) [`数学`](/tag/math.md) [`动态规划`](/tag/dynamic-programming.md) `1+` | 🟠 | [🀄️](https://leetcode.cn/problems/largest-divisible-subset) [🔗](https://leetcode.com/problems/largest-divisible-subset) | | 375 | 猜数字大小 II | [[✓]](/problem/0375.md) | [`数学`](/tag/math.md) [`动态规划`](/tag/dynamic-programming.md) [`博弈`](/tag/game-theory.md) | 🟠 | [🀄️](https://leetcode.cn/problems/guess-number-higher-or-lower-ii) [🔗](https://leetcode.com/problems/guess-number-higher-or-lower-ii) | diff --git a/src/tag/graph.md b/src/tag/graph.md index 94f3cf7c95..88c86e6ea2 100644 --- a/src/tag/graph.md +++ b/src/tag/graph.md @@ -26,7 +26,7 @@ | 261 | 以图判树 🔒 | | [`深度优先搜索`](/tag/depth-first-search.md) [`广度优先搜索`](/tag/breadth-first-search.md) [`并查集`](/tag/union-find.md) `1+` | 🟠 | [🀄️](https://leetcode.cn/problems/graph-valid-tree) [🔗](https://leetcode.com/problems/graph-valid-tree) | | 269 | 火星词典 🔒 | | [`深度优先搜索`](/tag/depth-first-search.md) [`广度优先搜索`](/tag/breadth-first-search.md) [`图`](/tag/graph.md) `3+` | 🔴 | [🀄️](https://leetcode.cn/problems/alien-dictionary) [🔗](https://leetcode.com/problems/alien-dictionary) | | 277 | 搜寻名人 🔒 | | [`图`](/tag/graph.md) [`双指针`](/tag/two-pointers.md) [`交互`](/tag/interactive.md) | 🟠 | [🀄️](https://leetcode.cn/problems/find-the-celebrity) [🔗](https://leetcode.com/problems/find-the-celebrity) | -| 310 | 最小高度树 | | [`深度优先搜索`](/tag/depth-first-search.md) [`广度优先搜索`](/tag/breadth-first-search.md) [`图`](/tag/graph.md) `1+` | 🟠 | [🀄️](https://leetcode.cn/problems/minimum-height-trees) [🔗](https://leetcode.com/problems/minimum-height-trees) | +| 310 | 最小高度树 | [[✓]](/problem/0310.md) | [`深度优先搜索`](/tag/depth-first-search.md) [`广度优先搜索`](/tag/breadth-first-search.md) [`图`](/tag/graph.md) `1+` | 🟠 | [🀄️](https://leetcode.cn/problems/minimum-height-trees) [🔗](https://leetcode.com/problems/minimum-height-trees) | | 323 | 无向图中连通分量的数目 🔒 | | [`深度优先搜索`](/tag/depth-first-search.md) [`广度优先搜索`](/tag/breadth-first-search.md) [`并查集`](/tag/union-find.md) `1+` | 🟠 | [🀄️](https://leetcode.cn/problems/number-of-connected-components-in-an-undirected-graph) [🔗](https://leetcode.com/problems/number-of-connected-components-in-an-undirected-graph) | | 329 | 矩阵中的最长递增路径 | | [`深度优先搜索`](/tag/depth-first-search.md) [`广度优先搜索`](/tag/breadth-first-search.md) [`图`](/tag/graph.md) `5+` | 🔴 | [🀄️](https://leetcode.cn/problems/longest-increasing-path-in-a-matrix) [🔗](https://leetcode.com/problems/longest-increasing-path-in-a-matrix) | | 332 | 重新安排行程 | | [`深度优先搜索`](/tag/depth-first-search.md) [`图`](/tag/graph.md) [`欧拉回路`](/tag/eulerian-circuit.md) | 🔴 | [🀄️](https://leetcode.cn/problems/reconstruct-itinerary) [🔗](https://leetcode.com/problems/reconstruct-itinerary) | diff --git a/src/tag/heap-priority-queue.md b/src/tag/heap-priority-queue.md index 49e7f03883..2dea1ca1ca 100644 --- a/src/tag/heap-priority-queue.md +++ b/src/tag/heap-priority-queue.md @@ -33,7 +33,7 @@ | 358 | K 距离间隔重排字符串 🔒 | | [`贪心`](/tag/greedy.md) [`哈希表`](/tag/hash-table.md) [`字符串`](/tag/string.md) `3+` | 🔴 | [🀄️](https://leetcode.cn/problems/rearrange-string-k-distance-apart) [🔗](https://leetcode.com/problems/rearrange-string-k-distance-apart) | | 373 | 查找和最小的 K 对数字 | [[✓]](/problem/0373.md) | [`数组`](/tag/array.md) [`堆(优先队列)`](/tag/heap-priority-queue.md) | 🟠 | [🀄️](https://leetcode.cn/problems/find-k-pairs-with-smallest-sums) [🔗](https://leetcode.com/problems/find-k-pairs-with-smallest-sums) | | 378 | 有序矩阵中第 K 小的元素 | [[✓]](/problem/0378.md) | [`数组`](/tag/array.md) [`二分查找`](/tag/binary-search.md) [`矩阵`](/tag/matrix.md) `2+` | 🟠 | [🀄️](https://leetcode.cn/problems/kth-smallest-element-in-a-sorted-matrix) [🔗](https://leetcode.com/problems/kth-smallest-element-in-a-sorted-matrix) | -| 407 | 接雨水 II | | [`广度优先搜索`](/tag/breadth-first-search.md) [`数组`](/tag/array.md) [`矩阵`](/tag/matrix.md) `1+` | 🔴 | [🀄️](https://leetcode.cn/problems/trapping-rain-water-ii) [🔗](https://leetcode.com/problems/trapping-rain-water-ii) | +| 407 | 接雨水 II | [[✓]](/problem/0407.md) | [`广度优先搜索`](/tag/breadth-first-search.md) [`数组`](/tag/array.md) [`矩阵`](/tag/matrix.md) `1+` | 🔴 | [🀄️](https://leetcode.cn/problems/trapping-rain-water-ii) [🔗](https://leetcode.com/problems/trapping-rain-water-ii) | | 420 | 强密码检验器 | | [`贪心`](/tag/greedy.md) [`字符串`](/tag/string.md) [`堆(优先队列)`](/tag/heap-priority-queue.md) | 🔴 | [🀄️](https://leetcode.cn/problems/strong-password-checker) [🔗](https://leetcode.com/problems/strong-password-checker) | | 451 | 根据字符出现频率排序 | [[✓]](/problem/0451.md) | [`哈希表`](/tag/hash-table.md) [`字符串`](/tag/string.md) [`桶排序`](/tag/bucket-sort.md) `3+` | 🟠 | [🀄️](https://leetcode.cn/problems/sort-characters-by-frequency) [🔗](https://leetcode.com/problems/sort-characters-by-frequency) | | 480 | 滑动窗口中位数 | | [`数组`](/tag/array.md) [`哈希表`](/tag/hash-table.md) [`滑动窗口`](/tag/sliding-window.md) `1+` | 🔴 | [🀄️](https://leetcode.cn/problems/sliding-window-median) [🔗](https://leetcode.com/problems/sliding-window-median) | diff --git a/src/tag/iterator.md b/src/tag/iterator.md index 761d9907ee..a23fe698a3 100644 --- a/src/tag/iterator.md +++ b/src/tag/iterator.md @@ -24,7 +24,7 @@ | 251 | 展开二维向量 🔒 | | [`设计`](/tag/design.md) [`数组`](/tag/array.md) [`双指针`](/tag/two-pointers.md) `1+` | 🟠 | [🀄️](https://leetcode.cn/problems/flatten-2d-vector) [🔗](https://leetcode.com/problems/flatten-2d-vector) | | 281 | 锯齿迭代器 🔒 | | [`设计`](/tag/design.md) [`队列`](/tag/queue.md) [`数组`](/tag/array.md) `1+` | 🟠 | [🀄️](https://leetcode.cn/problems/zigzag-iterator) [🔗](https://leetcode.com/problems/zigzag-iterator) | | 284 | 窥视迭代器 | [[✓]](/problem/0284.md) | [`设计`](/tag/design.md) [`数组`](/tag/array.md) [`迭代器`](/tag/iterator.md) | 🟠 | [🀄️](https://leetcode.cn/problems/peeking-iterator) [🔗](https://leetcode.com/problems/peeking-iterator) | -| 341 | 扁平化嵌套列表迭代器 | | [`栈`](/tag/stack.md) [`树`](/tag/tree.md) [`深度优先搜索`](/tag/depth-first-search.md) `3+` | 🟠 | [🀄️](https://leetcode.cn/problems/flatten-nested-list-iterator) [🔗](https://leetcode.com/problems/flatten-nested-list-iterator) | +| 341 | 扁平化嵌套列表迭代器 | [[✓]](/problem/0341.md) | [`栈`](/tag/stack.md) [`树`](/tag/tree.md) [`深度优先搜索`](/tag/depth-first-search.md) `3+` | 🟠 | [🀄️](https://leetcode.cn/problems/flatten-nested-list-iterator) [🔗](https://leetcode.com/problems/flatten-nested-list-iterator) | | 604 | 迭代压缩字符串 🔒 | | [`设计`](/tag/design.md) [`数组`](/tag/array.md) [`字符串`](/tag/string.md) `1+` | 🟢 | [🀄️](https://leetcode.cn/problems/design-compressed-string-iterator) [🔗](https://leetcode.com/problems/design-compressed-string-iterator) | | 900 | RLE 迭代器 | | [`设计`](/tag/design.md) [`数组`](/tag/array.md) [`计数`](/tag/counting.md) `1+` | 🟠 | [🀄️](https://leetcode.cn/problems/rle-iterator) [🔗](https://leetcode.com/problems/rle-iterator) | | 1286 | 字母组合迭代器 | | [`设计`](/tag/design.md) [`字符串`](/tag/string.md) [`回溯`](/tag/backtracking.md) `1+` | 🟠 | [🀄️](https://leetcode.cn/problems/iterator-for-combination) [🔗](https://leetcode.com/problems/iterator-for-combination) | diff --git a/src/tag/math.md b/src/tag/math.md index 8cef6dbb01..5f6143e274 100644 --- a/src/tag/math.md +++ b/src/tag/math.md @@ -62,14 +62,14 @@ | 292 | Nim 游戏 | [[✓]](/problem/0292.md) | [`脑筋急转弯`](/tag/brainteaser.md) [`数学`](/tag/math.md) [`博弈`](/tag/game-theory.md) | 🟢 | [🀄️](https://leetcode.cn/problems/nim-game) [🔗](https://leetcode.com/problems/nim-game) | | 294 | 翻转游戏 II 🔒 | | [`记忆化搜索`](/tag/memoization.md) [`数学`](/tag/math.md) [`动态规划`](/tag/dynamic-programming.md) `2+` | 🟠 | [🀄️](https://leetcode.cn/problems/flip-game-ii) [🔗](https://leetcode.com/problems/flip-game-ii) | | 296 | 最佳的碰头地点 🔒 | | [`数组`](/tag/array.md) [`数学`](/tag/math.md) [`矩阵`](/tag/matrix.md) `1+` | 🔴 | [🀄️](https://leetcode.cn/problems/best-meeting-point) [🔗](https://leetcode.com/problems/best-meeting-point) | -| 313 | 超级丑数 | | [`数组`](/tag/array.md) [`数学`](/tag/math.md) [`动态规划`](/tag/dynamic-programming.md) | 🟠 | [🀄️](https://leetcode.cn/problems/super-ugly-number) [🔗](https://leetcode.com/problems/super-ugly-number) | -| 319 | 灯泡开关 | | [`脑筋急转弯`](/tag/brainteaser.md) [`数学`](/tag/math.md) | 🟠 | [🀄️](https://leetcode.cn/problems/bulb-switcher) [🔗](https://leetcode.com/problems/bulb-switcher) | +| 313 | 超级丑数 | [[✓]](/problem/0313.md) | [`数组`](/tag/array.md) [`数学`](/tag/math.md) [`动态规划`](/tag/dynamic-programming.md) | 🟠 | [🀄️](https://leetcode.cn/problems/super-ugly-number) [🔗](https://leetcode.com/problems/super-ugly-number) | +| 319 | 灯泡开关 | [[✓]](/problem/0319.md) | [`脑筋急转弯`](/tag/brainteaser.md) [`数学`](/tag/math.md) | 🟠 | [🀄️](https://leetcode.cn/problems/bulb-switcher) [🔗](https://leetcode.com/problems/bulb-switcher) | | 326 | 3 的幂 | [[✓]](/problem/0326.md) | [`递归`](/tag/recursion.md) [`数学`](/tag/math.md) | 🟢 | [🀄️](https://leetcode.cn/problems/power-of-three) [🔗](https://leetcode.com/problems/power-of-three) | | 335 | 路径交叉 | | [`几何`](/tag/geometry.md) [`数组`](/tag/array.md) [`数学`](/tag/math.md) | 🔴 | [🀄️](https://leetcode.cn/problems/self-crossing) [🔗](https://leetcode.com/problems/self-crossing) | | 342 | 4的幂 | [[✓]](/problem/0342.md) | [`位运算`](/tag/bit-manipulation.md) [`递归`](/tag/recursion.md) [`数学`](/tag/math.md) | 🟢 | [🀄️](https://leetcode.cn/problems/power-of-four) [🔗](https://leetcode.com/problems/power-of-four) | | 343 | 整数拆分 | [[✓]](/problem/0343.md) | [`数学`](/tag/math.md) [`动态规划`](/tag/dynamic-programming.md) | 🟠 | [🀄️](https://leetcode.cn/problems/integer-break) [🔗](https://leetcode.com/problems/integer-break) | | 356 | 直线镜像 🔒 | | [`数组`](/tag/array.md) [`哈希表`](/tag/hash-table.md) [`数学`](/tag/math.md) | 🟠 | [🀄️](https://leetcode.cn/problems/line-reflection) [🔗](https://leetcode.com/problems/line-reflection) | -| 357 | 统计各位数字都不同的数字个数 | | [`数学`](/tag/math.md) [`动态规划`](/tag/dynamic-programming.md) [`回溯`](/tag/backtracking.md) | 🟠 | [🀄️](https://leetcode.cn/problems/count-numbers-with-unique-digits) [🔗](https://leetcode.com/problems/count-numbers-with-unique-digits) | +| 357 | 统计各位数字都不同的数字个数 | [[✓]](/problem/0357.md) | [`数学`](/tag/math.md) [`动态规划`](/tag/dynamic-programming.md) [`回溯`](/tag/backtracking.md) | 🟠 | [🀄️](https://leetcode.cn/problems/count-numbers-with-unique-digits) [🔗](https://leetcode.com/problems/count-numbers-with-unique-digits) | | 360 | 有序转化数组 🔒 | | [`数组`](/tag/array.md) [`数学`](/tag/math.md) [`双指针`](/tag/two-pointers.md) `1+` | 🟠 | [🀄️](https://leetcode.cn/problems/sort-transformed-array) [🔗](https://leetcode.com/problems/sort-transformed-array) | | 365 | 水壶问题 | | [`深度优先搜索`](/tag/depth-first-search.md) [`广度优先搜索`](/tag/breadth-first-search.md) [`数学`](/tag/math.md) | 🟠 | [🀄️](https://leetcode.cn/problems/water-and-jug-problem) [🔗](https://leetcode.com/problems/water-and-jug-problem) | | 367 | 有效的完全平方数 | [[✓]](/problem/0367.md) | [`数学`](/tag/math.md) [`二分查找`](/tag/binary-search.md) | 🟢 | [🀄️](https://leetcode.cn/problems/valid-perfect-square) [🔗](https://leetcode.com/problems/valid-perfect-square) | diff --git a/src/tag/matrix.md b/src/tag/matrix.md index 2dfd381bb2..96c86d1915 100644 --- a/src/tag/matrix.md +++ b/src/tag/matrix.md @@ -50,7 +50,7 @@ | 361 | 轰炸敌人 🔒 | | [`数组`](/tag/array.md) [`动态规划`](/tag/dynamic-programming.md) [`矩阵`](/tag/matrix.md) | 🟠 | [🀄️](https://leetcode.cn/problems/bomb-enemy) [🔗](https://leetcode.com/problems/bomb-enemy) | | 363 | 矩形区域不超过 K 的最大数值和 | | [`数组`](/tag/array.md) [`二分查找`](/tag/binary-search.md) [`矩阵`](/tag/matrix.md) `2+` | 🔴 | [🀄️](https://leetcode.cn/problems/max-sum-of-rectangle-no-larger-than-k) [🔗](https://leetcode.com/problems/max-sum-of-rectangle-no-larger-than-k) | | 378 | 有序矩阵中第 K 小的元素 | [[✓]](/problem/0378.md) | [`数组`](/tag/array.md) [`二分查找`](/tag/binary-search.md) [`矩阵`](/tag/matrix.md) `2+` | 🟠 | [🀄️](https://leetcode.cn/problems/kth-smallest-element-in-a-sorted-matrix) [🔗](https://leetcode.com/problems/kth-smallest-element-in-a-sorted-matrix) | -| 407 | 接雨水 II | | [`广度优先搜索`](/tag/breadth-first-search.md) [`数组`](/tag/array.md) [`矩阵`](/tag/matrix.md) `1+` | 🔴 | [🀄️](https://leetcode.cn/problems/trapping-rain-water-ii) [🔗](https://leetcode.com/problems/trapping-rain-water-ii) | +| 407 | 接雨水 II | [[✓]](/problem/0407.md) | [`广度优先搜索`](/tag/breadth-first-search.md) [`数组`](/tag/array.md) [`矩阵`](/tag/matrix.md) `1+` | 🔴 | [🀄️](https://leetcode.cn/problems/trapping-rain-water-ii) [🔗](https://leetcode.com/problems/trapping-rain-water-ii) | | 417 | 太平洋大西洋水流问题 | | [`深度优先搜索`](/tag/depth-first-search.md) [`广度优先搜索`](/tag/breadth-first-search.md) [`数组`](/tag/array.md) `1+` | 🟠 | [🀄️](https://leetcode.cn/problems/pacific-atlantic-water-flow) [🔗](https://leetcode.com/problems/pacific-atlantic-water-flow) | | 419 | 棋盘上的战舰 | | [`深度优先搜索`](/tag/depth-first-search.md) [`数组`](/tag/array.md) [`矩阵`](/tag/matrix.md) | 🟠 | [🀄️](https://leetcode.cn/problems/battleships-in-a-board) [🔗](https://leetcode.com/problems/battleships-in-a-board) | | 422 | 有效的单词方块 🔒 | | [`数组`](/tag/array.md) [`矩阵`](/tag/matrix.md) | 🟢 | [🀄️](https://leetcode.cn/problems/valid-word-square) [🔗](https://leetcode.com/problems/valid-word-square) | @@ -117,7 +117,7 @@ | 1254 | 统计封闭岛屿的数目 | | [`深度优先搜索`](/tag/depth-first-search.md) [`广度优先搜索`](/tag/breadth-first-search.md) [`并查集`](/tag/union-find.md) `2+` | 🟠 | [🀄️](https://leetcode.cn/problems/number-of-closed-islands) [🔗](https://leetcode.com/problems/number-of-closed-islands) | | 1260 | 二维网格迁移 | [[✓]](/problem/1260.md) | [`数组`](/tag/array.md) [`矩阵`](/tag/matrix.md) [`模拟`](/tag/simulation.md) | 🟢 | [🀄️](https://leetcode.cn/problems/shift-2d-grid) [🔗](https://leetcode.com/problems/shift-2d-grid) | | 1263 | 推箱子 | | [`广度优先搜索`](/tag/breadth-first-search.md) [`数组`](/tag/array.md) [`矩阵`](/tag/matrix.md) `1+` | 🔴 | [🀄️](https://leetcode.cn/problems/minimum-moves-to-move-a-box-to-their-target-location) [🔗](https://leetcode.com/problems/minimum-moves-to-move-a-box-to-their-target-location) | -| 1267 | 统计参与通信的服务器 | | [`深度优先搜索`](/tag/depth-first-search.md) [`广度优先搜索`](/tag/breadth-first-search.md) [`并查集`](/tag/union-find.md) `3+` | 🟠 | [🀄️](https://leetcode.cn/problems/count-servers-that-communicate) [🔗](https://leetcode.com/problems/count-servers-that-communicate) | +| 1267 | 统计参与通信的服务器 | [[✓]](/problem/1267.md) | [`深度优先搜索`](/tag/depth-first-search.md) [`广度优先搜索`](/tag/breadth-first-search.md) [`并查集`](/tag/union-find.md) `3+` | 🟠 | [🀄️](https://leetcode.cn/problems/count-servers-that-communicate) [🔗](https://leetcode.com/problems/count-servers-that-communicate) | | 1275 | 找出井字棋的获胜者 | [[✓]](/problem/1275.md) | [`数组`](/tag/array.md) [`哈希表`](/tag/hash-table.md) [`矩阵`](/tag/matrix.md) `1+` | 🟢 | [🀄️](https://leetcode.cn/problems/find-winner-on-a-tic-tac-toe-game) [🔗](https://leetcode.com/problems/find-winner-on-a-tic-tac-toe-game) | | 1277 | 统计全为 1 的正方形子矩阵 | [[✓]](/problem/1277.md) | [`数组`](/tag/array.md) [`动态规划`](/tag/dynamic-programming.md) [`矩阵`](/tag/matrix.md) | 🟠 | [🀄️](https://leetcode.cn/problems/count-square-submatrices-with-all-ones) [🔗](https://leetcode.com/problems/count-square-submatrices-with-all-ones) | | 1284 | 转化为全零矩阵的最少反转次数 | | [`位运算`](/tag/bit-manipulation.md) [`广度优先搜索`](/tag/breadth-first-search.md) [`数组`](/tag/array.md) `2+` | 🔴 | [🀄️](https://leetcode.cn/problems/minimum-number-of-flips-to-convert-binary-matrix-to-zero-matrix) [🔗](https://leetcode.com/problems/minimum-number-of-flips-to-convert-binary-matrix-to-zero-matrix) | @@ -156,7 +156,7 @@ | 1728 | 猫和老鼠 II | | [`图`](/tag/graph.md) [`拓扑排序`](/tag/topological-sort.md) [`记忆化搜索`](/tag/memoization.md) `5+` | 🔴 | [🀄️](https://leetcode.cn/problems/cat-and-mouse-ii) [🔗](https://leetcode.com/problems/cat-and-mouse-ii) | | 1730 | 获取食物的最短路径 🔒 | | [`广度优先搜索`](/tag/breadth-first-search.md) [`数组`](/tag/array.md) [`矩阵`](/tag/matrix.md) | 🟠 | [🀄️](https://leetcode.cn/problems/shortest-path-to-get-food) [🔗](https://leetcode.com/problems/shortest-path-to-get-food) | | 1738 | 找出第 K 大的异或坐标值 | | [`位运算`](/tag/bit-manipulation.md) [`数组`](/tag/array.md) [`分治`](/tag/divide-and-conquer.md) `5+` | 🟠 | [🀄️](https://leetcode.cn/problems/find-kth-largest-xor-coordinate-value) [🔗](https://leetcode.com/problems/find-kth-largest-xor-coordinate-value) | -| 1765 | 地图中的最高点 | | [`广度优先搜索`](/tag/breadth-first-search.md) [`数组`](/tag/array.md) [`矩阵`](/tag/matrix.md) | 🟠 | [🀄️](https://leetcode.cn/problems/map-of-highest-peak) [🔗](https://leetcode.com/problems/map-of-highest-peak) | +| 1765 | 地图中的最高点 | [[✓]](/problem/1765.md) | [`广度优先搜索`](/tag/breadth-first-search.md) [`数组`](/tag/array.md) [`矩阵`](/tag/matrix.md) | 🟠 | [🀄️](https://leetcode.cn/problems/map-of-highest-peak) [🔗](https://leetcode.com/problems/map-of-highest-peak) | | 1820 | 最多邀请的个数 🔒 | | [`深度优先搜索`](/tag/depth-first-search.md) [`图`](/tag/graph.md) [`数组`](/tag/array.md) `1+` | 🟠 | [🀄️](https://leetcode.cn/problems/maximum-number-of-accepted-invitations) [🔗](https://leetcode.com/problems/maximum-number-of-accepted-invitations) | | 1861 | 旋转盒子 | [[✓]](/problem/1861.md) | [`数组`](/tag/array.md) [`双指针`](/tag/two-pointers.md) [`矩阵`](/tag/matrix.md) | 🟠 | [🀄️](https://leetcode.cn/problems/rotating-the-box) [🔗](https://leetcode.com/problems/rotating-the-box) | | 1878 | 矩阵中最大的三个菱形和 | | [`数组`](/tag/array.md) [`数学`](/tag/math.md) [`矩阵`](/tag/matrix.md) `3+` | 🟠 | [🀄️](https://leetcode.cn/problems/get-biggest-three-rhombus-sums-in-a-grid) [🔗](https://leetcode.com/problems/get-biggest-three-rhombus-sums-in-a-grid) | @@ -172,7 +172,7 @@ | 1975 | 最大方阵和 | [[✓]](/problem/1975.md) | [`贪心`](/tag/greedy.md) [`数组`](/tag/array.md) [`矩阵`](/tag/matrix.md) | 🟠 | [🀄️](https://leetcode.cn/problems/maximum-matrix-sum) [🔗](https://leetcode.com/problems/maximum-matrix-sum) | | 1981 | 最小化目标值与所选元素的差 | | [`数组`](/tag/array.md) [`动态规划`](/tag/dynamic-programming.md) [`矩阵`](/tag/matrix.md) | 🟠 | [🀄️](https://leetcode.cn/problems/minimize-the-difference-between-target-and-chosen-elements) [🔗](https://leetcode.com/problems/minimize-the-difference-between-target-and-chosen-elements) | | 1992 | 找到所有的农场组 | | [`深度优先搜索`](/tag/depth-first-search.md) [`广度优先搜索`](/tag/breadth-first-search.md) [`数组`](/tag/array.md) `1+` | 🟠 | [🀄️](https://leetcode.cn/problems/find-all-groups-of-farmland) [🔗](https://leetcode.com/problems/find-all-groups-of-farmland) | -| 2017 | 网格游戏 | | [`数组`](/tag/array.md) [`矩阵`](/tag/matrix.md) [`前缀和`](/tag/prefix-sum.md) | 🟠 | [🀄️](https://leetcode.cn/problems/grid-game) [🔗](https://leetcode.com/problems/grid-game) | +| 2017 | 网格游戏 | [[✓]](/problem/2017.md) | [`数组`](/tag/array.md) [`矩阵`](/tag/matrix.md) [`前缀和`](/tag/prefix-sum.md) | 🟠 | [🀄️](https://leetcode.cn/problems/grid-game) [🔗](https://leetcode.com/problems/grid-game) | | 2018 | 判断单词是否能放入填字游戏内 | | [`数组`](/tag/array.md) [`枚举`](/tag/enumeration.md) [`矩阵`](/tag/matrix.md) | 🟠 | [🀄️](https://leetcode.cn/problems/check-if-word-can-be-placed-in-crossword) [🔗](https://leetcode.com/problems/check-if-word-can-be-placed-in-crossword) | | 2022 | 将一维数组转变成二维数组 | [[✓]](/problem/2022.md) | [`数组`](/tag/array.md) [`矩阵`](/tag/matrix.md) [`模拟`](/tag/simulation.md) | 🟢 | [🀄️](https://leetcode.cn/problems/convert-1d-array-into-2d-array) [🔗](https://leetcode.com/problems/convert-1d-array-into-2d-array) | | 2033 | 获取单值网格的最小操作数 | | [`数组`](/tag/array.md) [`数学`](/tag/math.md) [`矩阵`](/tag/matrix.md) `1+` | 🟠 | [🀄️](https://leetcode.cn/problems/minimum-operations-to-make-a-uni-value-grid) [🔗](https://leetcode.com/problems/minimum-operations-to-make-a-uni-value-grid) | @@ -218,7 +218,7 @@ | 2639 | 查询网格图中每一列的宽度 | | [`数组`](/tag/array.md) [`矩阵`](/tag/matrix.md) | 🟢 | [🀄️](https://leetcode.cn/problems/find-the-width-of-columns-of-a-grid) [🔗](https://leetcode.com/problems/find-the-width-of-columns-of-a-grid) | | 2643 | 一最多的行 | | [`数组`](/tag/array.md) [`矩阵`](/tag/matrix.md) | 🟢 | [🀄️](https://leetcode.cn/problems/row-with-maximum-ones) [🔗](https://leetcode.com/problems/row-with-maximum-ones) | | 2658 | 网格图中鱼的最大数目 | | [`深度优先搜索`](/tag/depth-first-search.md) [`广度优先搜索`](/tag/breadth-first-search.md) [`并查集`](/tag/union-find.md) `2+` | 🟠 | [🀄️](https://leetcode.cn/problems/maximum-number-of-fish-in-a-grid) [🔗](https://leetcode.com/problems/maximum-number-of-fish-in-a-grid) | -| 2661 | 找出叠涂元素 | | [`数组`](/tag/array.md) [`哈希表`](/tag/hash-table.md) [`矩阵`](/tag/matrix.md) | 🟠 | [🀄️](https://leetcode.cn/problems/first-completely-painted-row-or-column) [🔗](https://leetcode.com/problems/first-completely-painted-row-or-column) | +| 2661 | 找出叠涂元素 | [[✓]](/problem/2661.md) | [`数组`](/tag/array.md) [`哈希表`](/tag/hash-table.md) [`矩阵`](/tag/matrix.md) | 🟠 | [🀄️](https://leetcode.cn/problems/first-completely-painted-row-or-column) [🔗](https://leetcode.com/problems/first-completely-painted-row-or-column) | | 2664 | 巡逻的骑士 🔒 | | [`数组`](/tag/array.md) [`回溯`](/tag/backtracking.md) [`矩阵`](/tag/matrix.md) | 🟠 | [🀄️](https://leetcode.cn/problems/the-knights-tour) [🔗](https://leetcode.com/problems/the-knights-tour) | | 2679 | 矩阵中的和 | | [`数组`](/tag/array.md) [`矩阵`](/tag/matrix.md) [`排序`](/tag/sorting.md) `2+` | 🟠 | [🀄️](https://leetcode.cn/problems/sum-in-a-matrix) [🔗](https://leetcode.com/problems/sum-in-a-matrix) | | 2684 | 矩阵中移动的最大次数 | [[✓]](/problem/2684.md) | [`数组`](/tag/array.md) [`动态规划`](/tag/dynamic-programming.md) [`矩阵`](/tag/matrix.md) | 🟠 | [🀄️](https://leetcode.cn/problems/maximum-number-of-moves-in-a-grid) [🔗](https://leetcode.com/problems/maximum-number-of-moves-in-a-grid) | diff --git a/src/tag/prefix-sum.md b/src/tag/prefix-sum.md index 46e70e901b..2c8b92b658 100644 --- a/src/tag/prefix-sum.md +++ b/src/tag/prefix-sum.md @@ -103,7 +103,7 @@ | 1943 | 描述绘画结果 | | [`数组`](/tag/array.md) [`哈希表`](/tag/hash-table.md) [`前缀和`](/tag/prefix-sum.md) `1+` | 🟠 | [🀄️](https://leetcode.cn/problems/describe-the-painting) [🔗](https://leetcode.com/problems/describe-the-painting) | | 1983 | 范围和相等的最宽索引对 🔒 | | [`数组`](/tag/array.md) [`哈希表`](/tag/hash-table.md) [`前缀和`](/tag/prefix-sum.md) | 🟠 | [🀄️](https://leetcode.cn/problems/widest-pair-of-indices-with-equal-range-sum) [🔗](https://leetcode.com/problems/widest-pair-of-indices-with-equal-range-sum) | | 1991 | 找到数组的中间位置 | [[✓]](/problem/1991.md) | [`数组`](/tag/array.md) [`前缀和`](/tag/prefix-sum.md) | 🟢 | [🀄️](https://leetcode.cn/problems/find-the-middle-index-in-array) [🔗](https://leetcode.com/problems/find-the-middle-index-in-array) | -| 2017 | 网格游戏 | | [`数组`](/tag/array.md) [`矩阵`](/tag/matrix.md) [`前缀和`](/tag/prefix-sum.md) | 🟠 | [🀄️](https://leetcode.cn/problems/grid-game) [🔗](https://leetcode.com/problems/grid-game) | +| 2017 | 网格游戏 | [[✓]](/problem/2017.md) | [`数组`](/tag/array.md) [`矩阵`](/tag/matrix.md) [`前缀和`](/tag/prefix-sum.md) | 🟠 | [🀄️](https://leetcode.cn/problems/grid-game) [🔗](https://leetcode.com/problems/grid-game) | | 2021 | 街上最亮的位置 🔒 | | [`数组`](/tag/array.md) [`有序集合`](/tag/ordered-set.md) [`前缀和`](/tag/prefix-sum.md) | 🟠 | [🀄️](https://leetcode.cn/problems/brightest-position-on-street) [🔗](https://leetcode.com/problems/brightest-position-on-street) | | 2024 | 考试的最大困扰度 | | [`字符串`](/tag/string.md) [`二分查找`](/tag/binary-search.md) [`前缀和`](/tag/prefix-sum.md) `1+` | 🟠 | [🀄️](https://leetcode.cn/problems/maximize-the-confusion-of-an-exam) [🔗](https://leetcode.com/problems/maximize-the-confusion-of-an-exam) | | 2025 | 分割数组的最多方案数 | | [`数组`](/tag/array.md) [`哈希表`](/tag/hash-table.md) [`计数`](/tag/counting.md) `2+` | 🔴 | [🀄️](https://leetcode.cn/problems/maximum-number-of-ways-to-partition-an-array) [🔗](https://leetcode.com/problems/maximum-number-of-ways-to-partition-an-array) | diff --git a/src/tag/queue.md b/src/tag/queue.md index 96553e1661..ad90316290 100644 --- a/src/tag/queue.md +++ b/src/tag/queue.md @@ -24,7 +24,7 @@ | 232 | 用栈实现队列 | [[✓]](/problem/0232.md) | [`栈`](/tag/stack.md) [`设计`](/tag/design.md) [`队列`](/tag/queue.md) | 🟢 | [🀄️](https://leetcode.cn/problems/implement-queue-using-stacks) [🔗](https://leetcode.com/problems/implement-queue-using-stacks) | | 239 | 滑动窗口最大值 | [[✓]](/problem/0239.md) | [`队列`](/tag/queue.md) [`数组`](/tag/array.md) [`滑动窗口`](/tag/sliding-window.md) `2+` | 🔴 | [🀄️](https://leetcode.cn/problems/sliding-window-maximum) [🔗](https://leetcode.com/problems/sliding-window-maximum) | | 281 | 锯齿迭代器 🔒 | | [`设计`](/tag/design.md) [`队列`](/tag/queue.md) [`数组`](/tag/array.md) `1+` | 🟠 | [🀄️](https://leetcode.cn/problems/zigzag-iterator) [🔗](https://leetcode.com/problems/zigzag-iterator) | -| 341 | 扁平化嵌套列表迭代器 | | [`栈`](/tag/stack.md) [`树`](/tag/tree.md) [`深度优先搜索`](/tag/depth-first-search.md) `3+` | 🟠 | [🀄️](https://leetcode.cn/problems/flatten-nested-list-iterator) [🔗](https://leetcode.com/problems/flatten-nested-list-iterator) | +| 341 | 扁平化嵌套列表迭代器 | [[✓]](/problem/0341.md) | [`栈`](/tag/stack.md) [`树`](/tag/tree.md) [`深度优先搜索`](/tag/depth-first-search.md) `3+` | 🟠 | [🀄️](https://leetcode.cn/problems/flatten-nested-list-iterator) [🔗](https://leetcode.com/problems/flatten-nested-list-iterator) | | 346 | 数据流中的移动平均值 🔒 | [[✓]](/problem/0346.md) | [`设计`](/tag/design.md) [`队列`](/tag/queue.md) [`数组`](/tag/array.md) `1+` | 🟢 | [🀄️](https://leetcode.cn/problems/moving-average-from-data-stream) [🔗](https://leetcode.com/problems/moving-average-from-data-stream) | | 353 | 贪吃蛇 🔒 | | [`设计`](/tag/design.md) [`队列`](/tag/queue.md) [`数组`](/tag/array.md) `2+` | 🟠 | [🀄️](https://leetcode.cn/problems/design-snake-game) [🔗](https://leetcode.com/problems/design-snake-game) | | 362 | 敲击计数器 🔒 | | [`设计`](/tag/design.md) [`队列`](/tag/queue.md) [`数组`](/tag/array.md) `2+` | 🟠 | [🀄️](https://leetcode.cn/problems/design-hit-counter) [🔗](https://leetcode.com/problems/design-hit-counter) | diff --git a/src/tag/stack.md b/src/tag/stack.md index d6b6a4db9b..a759f727b7 100644 --- a/src/tag/stack.md +++ b/src/tag/stack.md @@ -43,8 +43,8 @@ | 272 | 最接近的二叉搜索树值 II 🔒 | | [`栈`](/tag/stack.md) [`树`](/tag/tree.md) [`深度优先搜索`](/tag/depth-first-search.md) `4+` | 🔴 | [🀄️](https://leetcode.cn/problems/closest-binary-search-tree-value-ii) [🔗](https://leetcode.com/problems/closest-binary-search-tree-value-ii) | | 316 | 去除重复字母 | [[✓]](/problem/0316.md) | [`栈`](/tag/stack.md) [`贪心`](/tag/greedy.md) [`字符串`](/tag/string.md) `1+` | 🟠 | [🀄️](https://leetcode.cn/problems/remove-duplicate-letters) [🔗](https://leetcode.com/problems/remove-duplicate-letters) | | 321 | 拼接最大数 | | [`栈`](/tag/stack.md) [`贪心`](/tag/greedy.md) [`数组`](/tag/array.md) `2+` | 🔴 | [🀄️](https://leetcode.cn/problems/create-maximum-number) [🔗](https://leetcode.com/problems/create-maximum-number) | -| 331 | 验证二叉树的前序序列化 | | [`栈`](/tag/stack.md) [`树`](/tag/tree.md) [`字符串`](/tag/string.md) `1+` | 🟠 | [🀄️](https://leetcode.cn/problems/verify-preorder-serialization-of-a-binary-tree) [🔗](https://leetcode.com/problems/verify-preorder-serialization-of-a-binary-tree) | -| 341 | 扁平化嵌套列表迭代器 | | [`栈`](/tag/stack.md) [`树`](/tag/tree.md) [`深度优先搜索`](/tag/depth-first-search.md) `3+` | 🟠 | [🀄️](https://leetcode.cn/problems/flatten-nested-list-iterator) [🔗](https://leetcode.com/problems/flatten-nested-list-iterator) | +| 331 | 验证二叉树的前序序列化 | [[✓]](/problem/0331.md) | [`栈`](/tag/stack.md) [`树`](/tag/tree.md) [`字符串`](/tag/string.md) `1+` | 🟠 | [🀄️](https://leetcode.cn/problems/verify-preorder-serialization-of-a-binary-tree) [🔗](https://leetcode.com/problems/verify-preorder-serialization-of-a-binary-tree) | +| 341 | 扁平化嵌套列表迭代器 | [[✓]](/problem/0341.md) | [`栈`](/tag/stack.md) [`树`](/tag/tree.md) [`深度优先搜索`](/tag/depth-first-search.md) `3+` | 🟠 | [🀄️](https://leetcode.cn/problems/flatten-nested-list-iterator) [🔗](https://leetcode.com/problems/flatten-nested-list-iterator) | | 364 | 嵌套列表加权和 II 🔒 | | [`栈`](/tag/stack.md) [`深度优先搜索`](/tag/depth-first-search.md) [`广度优先搜索`](/tag/breadth-first-search.md) | 🟠 | [🀄️](https://leetcode.cn/problems/nested-list-weight-sum-ii) [🔗](https://leetcode.com/problems/nested-list-weight-sum-ii) | | 385 | 迷你语法分析器 | | [`栈`](/tag/stack.md) [`深度优先搜索`](/tag/depth-first-search.md) [`字符串`](/tag/string.md) | 🟠 | [🀄️](https://leetcode.cn/problems/mini-parser) [🔗](https://leetcode.com/problems/mini-parser) | | 388 | 文件的最长绝对路径 | | [`栈`](/tag/stack.md) [`深度优先搜索`](/tag/depth-first-search.md) [`字符串`](/tag/string.md) | 🟠 | [🀄️](https://leetcode.cn/problems/longest-absolute-file-path) [🔗](https://leetcode.com/problems/longest-absolute-file-path) | diff --git a/src/tag/string.md b/src/tag/string.md index f1d8a2312d..2c90277a8d 100644 --- a/src/tag/string.md +++ b/src/tag/string.md @@ -98,11 +98,11 @@ | 297 | 二叉树的序列化与反序列化 | [[✓]](/problem/0297.md) | [`树`](/tag/tree.md) [`深度优先搜索`](/tag/depth-first-search.md) [`广度优先搜索`](/tag/breadth-first-search.md) `3+` | 🔴 | [🀄️](https://leetcode.cn/problems/serialize-and-deserialize-binary-tree) [🔗](https://leetcode.com/problems/serialize-and-deserialize-binary-tree) | | 299 | 猜数字游戏 | [[✓]](/problem/0299.md) | [`哈希表`](/tag/hash-table.md) [`字符串`](/tag/string.md) [`计数`](/tag/counting.md) | 🟠 | [🀄️](https://leetcode.cn/problems/bulls-and-cows) [🔗](https://leetcode.com/problems/bulls-and-cows) | | 301 | 删除无效的括号 | | [`广度优先搜索`](/tag/breadth-first-search.md) [`字符串`](/tag/string.md) [`回溯`](/tag/backtracking.md) | 🔴 | [🀄️](https://leetcode.cn/problems/remove-invalid-parentheses) [🔗](https://leetcode.com/problems/remove-invalid-parentheses) | -| 306 | 累加数 | | [`字符串`](/tag/string.md) [`回溯`](/tag/backtracking.md) | 🟠 | [🀄️](https://leetcode.cn/problems/additive-number) [🔗](https://leetcode.com/problems/additive-number) | +| 306 | 累加数 | [[✓]](/problem/0306.md) | [`字符串`](/tag/string.md) [`回溯`](/tag/backtracking.md) | 🟠 | [🀄️](https://leetcode.cn/problems/additive-number) [🔗](https://leetcode.com/problems/additive-number) | | 316 | 去除重复字母 | [[✓]](/problem/0316.md) | [`栈`](/tag/stack.md) [`贪心`](/tag/greedy.md) [`字符串`](/tag/string.md) `1+` | 🟠 | [🀄️](https://leetcode.cn/problems/remove-duplicate-letters) [🔗](https://leetcode.com/problems/remove-duplicate-letters) | -| 318 | 最大单词长度乘积 | | [`位运算`](/tag/bit-manipulation.md) [`数组`](/tag/array.md) [`字符串`](/tag/string.md) | 🟠 | [🀄️](https://leetcode.cn/problems/maximum-product-of-word-lengths) [🔗](https://leetcode.com/problems/maximum-product-of-word-lengths) | +| 318 | 最大单词长度乘积 | [[✓]](/problem/0318.md) | [`位运算`](/tag/bit-manipulation.md) [`数组`](/tag/array.md) [`字符串`](/tag/string.md) | 🟠 | [🀄️](https://leetcode.cn/problems/maximum-product-of-word-lengths) [🔗](https://leetcode.com/problems/maximum-product-of-word-lengths) | | 320 | 列举单词的全部缩写 🔒 | | [`位运算`](/tag/bit-manipulation.md) [`字符串`](/tag/string.md) [`回溯`](/tag/backtracking.md) | 🟠 | [🀄️](https://leetcode.cn/problems/generalized-abbreviation) [🔗](https://leetcode.com/problems/generalized-abbreviation) | -| 331 | 验证二叉树的前序序列化 | | [`栈`](/tag/stack.md) [`树`](/tag/tree.md) [`字符串`](/tag/string.md) `1+` | 🟠 | [🀄️](https://leetcode.cn/problems/verify-preorder-serialization-of-a-binary-tree) [🔗](https://leetcode.com/problems/verify-preorder-serialization-of-a-binary-tree) | +| 331 | 验证二叉树的前序序列化 | [[✓]](/problem/0331.md) | [`栈`](/tag/stack.md) [`树`](/tag/tree.md) [`字符串`](/tag/string.md) `1+` | 🟠 | [🀄️](https://leetcode.cn/problems/verify-preorder-serialization-of-a-binary-tree) [🔗](https://leetcode.com/problems/verify-preorder-serialization-of-a-binary-tree) | | 336 | 回文对 | | [`字典树`](/tag/trie.md) [`数组`](/tag/array.md) [`哈希表`](/tag/hash-table.md) `1+` | 🔴 | [🀄️](https://leetcode.cn/problems/palindrome-pairs) [🔗](https://leetcode.com/problems/palindrome-pairs) | | 340 | 至多包含 K 个不同字符的最长子串 🔒 | | [`哈希表`](/tag/hash-table.md) [`字符串`](/tag/string.md) [`滑动窗口`](/tag/sliding-window.md) | 🟠 | [🀄️](https://leetcode.cn/problems/longest-substring-with-at-most-k-distinct-characters) [🔗](https://leetcode.com/problems/longest-substring-with-at-most-k-distinct-characters) | | 344 | 反转字符串 | [[✓]](/problem/0344.md) | [`双指针`](/tag/two-pointers.md) [`字符串`](/tag/string.md) | 🟢 | [🀄️](https://leetcode.cn/problems/reverse-string) [🔗](https://leetcode.com/problems/reverse-string) | diff --git a/src/tag/topological-sort.md b/src/tag/topological-sort.md index 4c4f07c2cb..3011671291 100644 --- a/src/tag/topological-sort.md +++ b/src/tag/topological-sort.md @@ -23,7 +23,7 @@ | 207 | 课程表 | [[✓]](/problem/0207.md) | [`深度优先搜索`](/tag/depth-first-search.md) [`广度优先搜索`](/tag/breadth-first-search.md) [`图`](/tag/graph.md) `1+` | 🟠 | [🀄️](https://leetcode.cn/problems/course-schedule) [🔗](https://leetcode.com/problems/course-schedule) | | 210 | 课程表 II | [[✓]](/problem/0210.md) | [`深度优先搜索`](/tag/depth-first-search.md) [`广度优先搜索`](/tag/breadth-first-search.md) [`图`](/tag/graph.md) `1+` | 🟠 | [🀄️](https://leetcode.cn/problems/course-schedule-ii) [🔗](https://leetcode.com/problems/course-schedule-ii) | | 269 | 火星词典 🔒 | | [`深度优先搜索`](/tag/depth-first-search.md) [`广度优先搜索`](/tag/breadth-first-search.md) [`图`](/tag/graph.md) `3+` | 🔴 | [🀄️](https://leetcode.cn/problems/alien-dictionary) [🔗](https://leetcode.com/problems/alien-dictionary) | -| 310 | 最小高度树 | | [`深度优先搜索`](/tag/depth-first-search.md) [`广度优先搜索`](/tag/breadth-first-search.md) [`图`](/tag/graph.md) `1+` | 🟠 | [🀄️](https://leetcode.cn/problems/minimum-height-trees) [🔗](https://leetcode.com/problems/minimum-height-trees) | +| 310 | 最小高度树 | [[✓]](/problem/0310.md) | [`深度优先搜索`](/tag/depth-first-search.md) [`广度优先搜索`](/tag/breadth-first-search.md) [`图`](/tag/graph.md) `1+` | 🟠 | [🀄️](https://leetcode.cn/problems/minimum-height-trees) [🔗](https://leetcode.com/problems/minimum-height-trees) | | 329 | 矩阵中的最长递增路径 | | [`深度优先搜索`](/tag/depth-first-search.md) [`广度优先搜索`](/tag/breadth-first-search.md) [`图`](/tag/graph.md) `5+` | 🔴 | [🀄️](https://leetcode.cn/problems/longest-increasing-path-in-a-matrix) [🔗](https://leetcode.com/problems/longest-increasing-path-in-a-matrix) | | 444 | 序列重建 🔒 | | [`图`](/tag/graph.md) [`拓扑排序`](/tag/topological-sort.md) [`数组`](/tag/array.md) | 🟠 | [🀄️](https://leetcode.cn/problems/sequence-reconstruction) [🔗](https://leetcode.com/problems/sequence-reconstruction) | | 631 | 设计 Excel 求和公式 🔒 | | [`图`](/tag/graph.md) [`设计`](/tag/design.md) [`拓扑排序`](/tag/topological-sort.md) `2+` | 🔴 | [🀄️](https://leetcode.cn/problems/design-excel-sum-formula) [🔗](https://leetcode.com/problems/design-excel-sum-formula) | diff --git a/src/tag/tree.md b/src/tag/tree.md index 7fb42950dd..fd49247fd7 100644 --- a/src/tag/tree.md +++ b/src/tag/tree.md @@ -63,10 +63,10 @@ | 297 | 二叉树的序列化与反序列化 | [[✓]](/problem/0297.md) | [`树`](/tag/tree.md) [`深度优先搜索`](/tag/depth-first-search.md) [`广度优先搜索`](/tag/breadth-first-search.md) `3+` | 🔴 | [🀄️](https://leetcode.cn/problems/serialize-and-deserialize-binary-tree) [🔗](https://leetcode.com/problems/serialize-and-deserialize-binary-tree) | | 298 | 二叉树最长连续序列 🔒 | | [`树`](/tag/tree.md) [`深度优先搜索`](/tag/depth-first-search.md) [`二叉树`](/tag/binary-tree.md) | 🟠 | [🀄️](https://leetcode.cn/problems/binary-tree-longest-consecutive-sequence) [🔗](https://leetcode.com/problems/binary-tree-longest-consecutive-sequence) | | 314 | 二叉树的垂直遍历 🔒 | | [`树`](/tag/tree.md) [`深度优先搜索`](/tag/depth-first-search.md) [`广度优先搜索`](/tag/breadth-first-search.md) `3+` | 🟠 | [🀄️](https://leetcode.cn/problems/binary-tree-vertical-order-traversal) [🔗](https://leetcode.com/problems/binary-tree-vertical-order-traversal) | -| 331 | 验证二叉树的前序序列化 | | [`栈`](/tag/stack.md) [`树`](/tag/tree.md) [`字符串`](/tag/string.md) `1+` | 🟠 | [🀄️](https://leetcode.cn/problems/verify-preorder-serialization-of-a-binary-tree) [🔗](https://leetcode.com/problems/verify-preorder-serialization-of-a-binary-tree) | +| 331 | 验证二叉树的前序序列化 | [[✓]](/problem/0331.md) | [`栈`](/tag/stack.md) [`树`](/tag/tree.md) [`字符串`](/tag/string.md) `1+` | 🟠 | [🀄️](https://leetcode.cn/problems/verify-preorder-serialization-of-a-binary-tree) [🔗](https://leetcode.com/problems/verify-preorder-serialization-of-a-binary-tree) | | 333 | 最大二叉搜索子树 🔒 | | [`树`](/tag/tree.md) [`深度优先搜索`](/tag/depth-first-search.md) [`二叉搜索树`](/tag/binary-search-tree.md) `2+` | 🟠 | [🀄️](https://leetcode.cn/problems/largest-bst-subtree) [🔗](https://leetcode.com/problems/largest-bst-subtree) | -| 337 | 打家劫舍 III | | [`树`](/tag/tree.md) [`深度优先搜索`](/tag/depth-first-search.md) [`动态规划`](/tag/dynamic-programming.md) `1+` | 🟠 | [🀄️](https://leetcode.cn/problems/house-robber-iii) [🔗](https://leetcode.com/problems/house-robber-iii) | -| 341 | 扁平化嵌套列表迭代器 | | [`栈`](/tag/stack.md) [`树`](/tag/tree.md) [`深度优先搜索`](/tag/depth-first-search.md) `3+` | 🟠 | [🀄️](https://leetcode.cn/problems/flatten-nested-list-iterator) [🔗](https://leetcode.com/problems/flatten-nested-list-iterator) | +| 337 | 打家劫舍 III | [[✓]](/problem/0337.md) | [`树`](/tag/tree.md) [`深度优先搜索`](/tag/depth-first-search.md) [`动态规划`](/tag/dynamic-programming.md) `1+` | 🟠 | [🀄️](https://leetcode.cn/problems/house-robber-iii) [🔗](https://leetcode.com/problems/house-robber-iii) | +| 341 | 扁平化嵌套列表迭代器 | [[✓]](/problem/0341.md) | [`栈`](/tag/stack.md) [`树`](/tag/tree.md) [`深度优先搜索`](/tag/depth-first-search.md) `3+` | 🟠 | [🀄️](https://leetcode.cn/problems/flatten-nested-list-iterator) [🔗](https://leetcode.com/problems/flatten-nested-list-iterator) | | 366 | 寻找二叉树的叶子节点 🔒 | [[✓]](/problem/0366.md) | [`树`](/tag/tree.md) [`深度优先搜索`](/tag/depth-first-search.md) [`二叉树`](/tag/binary-tree.md) | 🟠 | [🀄️](https://leetcode.cn/problems/find-leaves-of-binary-tree) [🔗](https://leetcode.com/problems/find-leaves-of-binary-tree) | | 404 | 左叶子之和 | [[✓]](/problem/0404.md) | [`树`](/tag/tree.md) [`深度优先搜索`](/tag/depth-first-search.md) [`广度优先搜索`](/tag/breadth-first-search.md) `1+` | 🟢 | [🀄️](https://leetcode.cn/problems/sum-of-left-leaves) [🔗](https://leetcode.com/problems/sum-of-left-leaves) | | 426 | 将二叉搜索树转化为排序的双向链表 🔒 | [[✓]](/problem/0426.md) | [`栈`](/tag/stack.md) [`树`](/tag/tree.md) [`深度优先搜索`](/tag/depth-first-search.md) `4+` | 🟠 | [🀄️](https://leetcode.cn/problems/convert-binary-search-tree-to-sorted-doubly-linked-list) [🔗](https://leetcode.com/problems/convert-binary-search-tree-to-sorted-doubly-linked-list) | diff --git a/src/tag/union-find.md b/src/tag/union-find.md index 3a90e9d407..89160ea378 100644 --- a/src/tag/union-find.md +++ b/src/tag/union-find.md @@ -57,7 +57,7 @@ | 1202 | 交换字符串中的元素 | | [`深度优先搜索`](/tag/depth-first-search.md) [`广度优先搜索`](/tag/breadth-first-search.md) [`并查集`](/tag/union-find.md) `4+` | 🟠 | [🀄️](https://leetcode.cn/problems/smallest-string-with-swaps) [🔗](https://leetcode.com/problems/smallest-string-with-swaps) | | 1254 | 统计封闭岛屿的数目 | | [`深度优先搜索`](/tag/depth-first-search.md) [`广度优先搜索`](/tag/breadth-first-search.md) [`并查集`](/tag/union-find.md) `2+` | 🟠 | [🀄️](https://leetcode.cn/problems/number-of-closed-islands) [🔗](https://leetcode.com/problems/number-of-closed-islands) | | 1258 | 近义词句子 🔒 | | [`并查集`](/tag/union-find.md) [`数组`](/tag/array.md) [`哈希表`](/tag/hash-table.md) `2+` | 🟠 | [🀄️](https://leetcode.cn/problems/synonymous-sentences) [🔗](https://leetcode.com/problems/synonymous-sentences) | -| 1267 | 统计参与通信的服务器 | | [`深度优先搜索`](/tag/depth-first-search.md) [`广度优先搜索`](/tag/breadth-first-search.md) [`并查集`](/tag/union-find.md) `3+` | 🟠 | [🀄️](https://leetcode.cn/problems/count-servers-that-communicate) [🔗](https://leetcode.com/problems/count-servers-that-communicate) | +| 1267 | 统计参与通信的服务器 | [[✓]](/problem/1267.md) | [`深度优先搜索`](/tag/depth-first-search.md) [`广度优先搜索`](/tag/breadth-first-search.md) [`并查集`](/tag/union-find.md) `3+` | 🟠 | [🀄️](https://leetcode.cn/problems/count-servers-that-communicate) [🔗](https://leetcode.com/problems/count-servers-that-communicate) | | 1319 | 连通网络的操作次数 | | [`深度优先搜索`](/tag/depth-first-search.md) [`广度优先搜索`](/tag/breadth-first-search.md) [`并查集`](/tag/union-find.md) `1+` | 🟠 | [🀄️](https://leetcode.cn/problems/number-of-operations-to-make-network-connected) [🔗](https://leetcode.com/problems/number-of-operations-to-make-network-connected) | | 1361 | 验证二叉树 | | [`树`](/tag/tree.md) [`深度优先搜索`](/tag/depth-first-search.md) [`广度优先搜索`](/tag/breadth-first-search.md) `3+` | 🟠 | [🀄️](https://leetcode.cn/problems/validate-binary-tree-nodes) [🔗](https://leetcode.com/problems/validate-binary-tree-nodes) | | 1391 | 检查网格中是否存在有效路径 | | [`深度优先搜索`](/tag/depth-first-search.md) [`广度优先搜索`](/tag/breadth-first-search.md) [`并查集`](/tag/union-find.md) `2+` | 🟠 | [🀄️](https://leetcode.cn/problems/check-if-there-is-a-valid-path-in-a-grid) [🔗](https://leetcode.com/problems/check-if-there-is-a-valid-path-in-a-grid) |