From a7c50eba16df5a21da272023954bd7db09171213 Mon Sep 17 00:00:00 2001 From: Shuo Date: Fri, 29 Jan 2021 11:52:33 +0800 Subject: [PATCH] A: new --- README.md | 31 +++-- problems/array-of-doubled-pairs/README.md | 25 ++-- problems/asteroid-collision/README.md | 4 +- .../README.md | 2 +- .../best-time-to-buy-and-sell-stock/README.md | 23 ++-- .../binary-tree-maximum-path-sum/README.md | 8 +- .../binary-tree-preorder-traversal/README.md | 7 +- problems/boats-to-save-people/README.md | 39 +++---- problems/building-boxes/README.md | 76 ++++++++++++ problems/burst-balloons/README.md | 6 +- .../README.md | 27 ++--- problems/cat-and-mouse-ii/README.md | 107 +++++++++++++++++ .../README.md | 68 +++++++++++ .../README.md | 6 +- .../README.md | 35 ++++++ problems/coin-path/README.md | 2 +- .../README.md | 11 +- problems/count-complete-tree-nodes/README.md | 45 +++++--- problems/count-number-of-teams/README.md | 13 ++- .../README.md | 20 +++- .../README.md | 57 +++++++++ problems/decode-ways/README.md | 5 +- problems/decode-xored-permutation/README.md | 67 +++++++++++ problems/delete-and-earn/README.md | 2 +- .../README.md | 1 + problems/design-hashset/README.md | 54 +++++---- .../README.md | 13 ++- .../README.md | 10 +- .../find-distance-in-a-binary-tree/README.md | 30 +++++ problems/find-followers-count/README.md | 14 +++ .../find-followers-count/mysql_schemas.sql | 6 + problems/find-k-closest-elements/README.md | 7 +- .../README.md | 67 +++++++++++ .../README.md | 2 +- .../README.md | 38 ++++-- problems/find-the-highest-altitude/README.md | 56 +++++++++ .../README.md | 2 + problems/first-missing-positive/README.md | 7 +- .../README.md | 50 +++++--- problems/gray-code/README.md | 2 +- problems/house-robber-ii/README.md | 2 +- problems/house-robber-iii/README.md | 2 +- problems/house-robber/README.md | 2 +- problems/insert-interval/README.md | 2 +- .../interval-list-intersections/README.md | 52 ++++++--- problems/invalid-transactions/README.md | 16 +-- problems/invalid-tweets/README.md | 2 +- .../k-concatenation-maximum-sum/README.md | 14 +-- .../k-th-smallest-prime-fraction/README.md | 39 ++++--- problems/keyboard-row/README.md | 42 +++++-- .../kth-smallest-element-in-a-bst/README.md | 33 ++---- problems/largest-subarray-length-k/README.md | 2 +- .../README.md | 78 +++++++++++++ .../README.md | 64 ++++++++++ problems/lfu-cache/README.md | 30 +++-- .../README.md | 9 +- .../longest-consecutive-sequence/README.md | 5 +- .../README.md | 4 +- .../README.md | 6 +- .../README.md | 4 +- problems/maximum-product-subarray/README.md | 2 +- problems/meeting-scheduler/README.md | 2 + problems/merge-intervals/README.md | 2 +- problems/merge-sorted-array/README.md | 6 +- problems/minimize-malware-spread-ii/README.md | 70 +++++------ problems/minimize-malware-spread/README.md | 6 +- .../README.md | 71 ++++++++++++ .../README.md | 5 +- problems/missing-ranges/README.md | 2 +- problems/nested-list-weight-sum/README.md | 1 + problems/network-delay-time/README.md | 43 ++++--- problems/next-greater-element-i/README.md | 66 ++++++----- problems/non-decreasing-array/README.md | 9 +- .../README.md | 2 +- .../README.md | 66 +++++++++++ problems/paint-fence/README.md | 2 +- problems/paint-house/README.md | 2 +- problems/palindrome-number/README.md | 7 +- problems/pancake-sorting/README.md | 17 ++- problems/path-sum-ii/README.md | 42 ++++--- problems/path-sum/README.md | 39 +++++-- .../peak-index-in-a-mountain-array/README.md | 5 +- problems/perfect-squares/README.md | 30 +++-- .../products-worth-over-invoices/README.md | 2 +- .../projection-area-of-3d-shapes/README.md | 104 ++++------------- problems/range-module/README.md | 2 +- problems/range-sum-query-mutable/README.md | 38 ++++-- .../README.md | 67 +++++------ .../README.md | 2 +- problems/reorder-data-in-log-files/README.md | 31 +++-- problems/reverse-integer/README.md | 4 +- problems/robot-bounded-in-circle/README.md | 40 +++---- .../search-in-a-binary-search-tree/README.md | 36 +++--- problems/set-mismatch/README.md | 35 +++--- problems/shortest-path-to-get-food/README.md | 40 +++++++ .../README.md | 5 +- problems/sort-colors/README.md | 19 +-- problems/sort-the-matrix-diagonally/README.md | 13 ++- problems/string-to-integer-atoi/README.md | 80 ++++++++++--- problems/subsets-ii/README.md | 35 +++--- problems/subsets/README.md | 4 +- problems/sum-of-subarray-minimums/README.md | 27 +---- problems/summary-ranges/README.md | 2 +- problems/surface-area-of-3d-shapes/README.md | 6 +- .../README.md | 14 +++ .../mysql_schemas.sql | 6 + problems/third-maximum-number/README.md | 4 +- problems/three-equal-parts/README.md | 51 ++++---- problems/trapping-rain-water/README.md | 1 + problems/trim-a-binary-search-tree/README.md | 3 +- problems/trips-and-users/README.md | 109 ++++++++++++------ problems/tuple-with-same-product/README.md | 75 ++++++++++++ .../README.md | 18 ++- problems/ugly-number-iii/README.md | 10 +- .../unique-binary-search-trees-ii/README.md | 33 +++--- problems/unique-binary-search-trees/README.md | 24 ++-- problems/valid-number/README.md | 83 ++++++++----- .../README.md | 18 ++- problems/walking-robot-simulation/README.md | 31 ++++- problems/word-ladder/README.md | 24 ++-- problems/word-pattern-ii/README.md | 2 +- problems/word-pattern/README.md | 2 +- readme/1-300.md | 4 +- readme/301-600.md | 2 +- readme/601-900.md | 4 +- readme/901-1200.md | 4 +- tag/README.md | 2 +- tag/array/README.md | 16 ++- tag/backtracking/README.md | 4 +- tag/binary-indexed-tree/README.md | 7 ++ tag/binary-search-tree/README.md | 4 + tag/binary-search/README.md | 6 +- tag/bit-manipulation/README.md | 1 + tag/breadth-first-search/README.md | 78 ------------- tag/depth-first-search/README.md | 5 +- tag/design/README.md | 2 +- tag/dynamic-programming/README.md | 7 +- tag/graph/README.md | 2 + tag/greedy/README.md | 11 +- tag/hash-table/README.md | 2 + tag/heap/README.md | 3 +- tag/line-sweep/README.md | 6 + tag/linked-list/README.md | 2 +- tag/math/README.md | 6 +- tag/memoization/README.md | 1 + tag/ordered-map/README.md | 14 --- tag/queue/README.md | 9 -- tag/recursion/README.md | 1 + tag/rejection-sampling/README.md | 2 + tag/reservoir-sampling/README.md | 2 + tag/segment-tree/README.md | 16 --- tag/sliding-window/README.md | 1 + tag/sort/README.md | 4 +- tag/stack/README.md | 4 +- tag/string/README.md | 4 +- tag/tags.json | 10 +- tag/tree/README.md | 3 +- tag/trie/README.md | 2 +- tag/two-pointers/README.md | 7 +- tag/union-find/README.md | 1 + 160 files changed, 2232 insertions(+), 1077 deletions(-) create mode 100644 problems/building-boxes/README.md create mode 100644 problems/cat-and-mouse-ii/README.md create mode 100644 problems/change-minimum-characters-to-satisfy-one-of-three-conditions/README.md create mode 100644 problems/checking-existence-of-edge-length-limited-paths-ii/README.md create mode 100644 problems/count-ways-to-make-array-with-product/README.md create mode 100644 problems/decode-xored-permutation/README.md create mode 100644 problems/find-distance-in-a-binary-tree/README.md create mode 100644 problems/find-followers-count/README.md create mode 100644 problems/find-followers-count/mysql_schemas.sql create mode 100644 problems/find-kth-largest-xor-coordinate-value/README.md create mode 100644 problems/find-the-highest-altitude/README.md create mode 100644 problems/largest-submatrix-with-rearrangements/README.md create mode 100644 problems/latest-time-by-replacing-hidden-digits/README.md create mode 100644 problems/minimum-number-of-people-to-teach/README.md create mode 100644 problems/number-of-rectangles-that-can-form-the-largest-square/README.md create mode 100644 problems/shortest-path-to-get-food/README.md create mode 100644 problems/the-number-of-employees-which-report-to-each-employee/README.md create mode 100644 problems/the-number-of-employees-which-report-to-each-employee/mysql_schemas.sql create mode 100644 problems/tuple-with-same-product/README.md diff --git a/README.md b/README.md index f6db8115f..49353f20e 100644 --- a/README.md +++ b/README.md @@ -70,6 +70,23 @@ LeetCode Problems' Solutions | # | Title | Solution | Difficulty | | :-: | - | - | :-: | +| 1740 | [Find Distance in a Binary Tree](https://leetcode.com/problems/find-distance-in-a-binary-tree) 🔒 | [Go](problems/find-distance-in-a-binary-tree) | Easy | +| 1739 | [Building Boxes](https://leetcode.com/problems/building-boxes "放置盒子") | [Go](problems/building-boxes) | Hard | +| 1738 | [Find Kth Largest XOR Coordinate Value](https://leetcode.com/problems/find-kth-largest-xor-coordinate-value "找出第 K 大的异或坐标值") | [Go](problems/find-kth-largest-xor-coordinate-value) | Medium | +| 1737 | [Change Minimum Characters to Satisfy One of Three Conditions](https://leetcode.com/problems/change-minimum-characters-to-satisfy-one-of-three-conditions "满足三条件之一需改变的最少字符数") | [Go](problems/change-minimum-characters-to-satisfy-one-of-three-conditions) | Medium | +| 1736 | [Latest Time by Replacing Hidden Digits](https://leetcode.com/problems/latest-time-by-replacing-hidden-digits "替换隐藏数字得到的最晚时间") | [Go](problems/latest-time-by-replacing-hidden-digits) | Easy | +| 1735 | [Count Ways to Make Array With Product](https://leetcode.com/problems/count-ways-to-make-array-with-product "生成乘积数组的方案数") | [Go](problems/count-ways-to-make-array-with-product) | Hard | +| 1734 | [Decode XORed Permutation](https://leetcode.com/problems/decode-xored-permutation "解码异或后的排列") | [Go](problems/decode-xored-permutation) | Medium | +| 1733 | [Minimum Number of People to Teach](https://leetcode.com/problems/minimum-number-of-people-to-teach "需要教语言的最少人数") | [Go](problems/minimum-number-of-people-to-teach) | Medium | +| 1732 | [Find the Highest Altitude](https://leetcode.com/problems/find-the-highest-altitude "找到最高海拔") | [Go](problems/find-the-highest-altitude) | Easy | +| 1731 | [The Number of Employees Which Report to Each Employee](https://leetcode.com/problems/the-number-of-employees-which-report-to-each-employee) 🔒 | [MySQL](problems/the-number-of-employees-which-report-to-each-employee) | Easy | +| 1730 | [Shortest Path to Get Food](https://leetcode.com/problems/shortest-path-to-get-food) 🔒 | [Go](problems/shortest-path-to-get-food) | Medium | +| 1729 | [Find Followers Count](https://leetcode.com/problems/find-followers-count) 🔒 | [MySQL](problems/find-followers-count) | Easy | +| 1728 | [Cat and Mouse II](https://leetcode.com/problems/cat-and-mouse-ii "猫和老鼠 II") | [Go](problems/cat-and-mouse-ii) | Hard | +| 1727 | [Largest Submatrix With Rearrangements](https://leetcode.com/problems/largest-submatrix-with-rearrangements "重新排列后的最大子矩阵") | [Go](problems/largest-submatrix-with-rearrangements) | Medium | +| 1726 | [Tuple with Same Product](https://leetcode.com/problems/tuple-with-same-product "同积元组") | [Go](problems/tuple-with-same-product) | Medium | +| 1725 | [Number Of Rectangles That Can Form The Largest Square](https://leetcode.com/problems/number-of-rectangles-that-can-form-the-largest-square "可以形成最大正方形的矩形数目") | [Go](problems/number-of-rectangles-that-can-form-the-largest-square) | Easy | +| 1724 | [Checking Existence of Edge Length Limited Paths II](https://leetcode.com/problems/checking-existence-of-edge-length-limited-paths-ii) 🔒 | [Go](problems/checking-existence-of-edge-length-limited-paths-ii) | Hard | | 1723 | [Find Minimum Time to Finish All Jobs](https://leetcode.com/problems/find-minimum-time-to-finish-all-jobs "完成所有工作的最短时间") | [Go](problems/find-minimum-time-to-finish-all-jobs) | Hard | | 1722 | [Minimize Hamming Distance After Swap Operations](https://leetcode.com/problems/minimize-hamming-distance-after-swap-operations "执行交换操作后的最小汉明距离") | [Go](problems/minimize-hamming-distance-after-swap-operations) | Medium | | 1721 | [Swapping Nodes in a Linked List](https://leetcode.com/problems/swapping-nodes-in-a-linked-list "交换链表中的节点") | [Go](problems/swapping-nodes-in-a-linked-list) | Medium | @@ -85,7 +102,7 @@ LeetCode Problems' Solutions | 1711 | [Count Good Meals](https://leetcode.com/problems/count-good-meals "大餐计数") | [Go](problems/count-good-meals) | Medium | | 1710 | [Maximum Units on a Truck](https://leetcode.com/problems/maximum-units-on-a-truck "卡车上的最大单元数") | [Go](problems/maximum-units-on-a-truck) | Easy | | 1709 | [Biggest Window Between Visits](https://leetcode.com/problems/biggest-window-between-visits) 🔒 | [MySQL](problems/biggest-window-between-visits) | Medium | -| 1708 | [Largest Subarray Length K](https://leetcode.com/problems/largest-subarray-length-k) 🔒 | [Go](problems/largest-subarray-length-k) | Easy | +| 1708 | [Largest Subarray Length K](https://leetcode.com/problems/largest-subarray-length-k "长度为 K 的最大子数组") 🔒 | [Go](problems/largest-subarray-length-k) | Easy | | 1707 | [Maximum XOR With an Element From Array](https://leetcode.com/problems/maximum-xor-with-an-element-from-array "与数组中元素的最大异或值") | [Go](problems/maximum-xor-with-an-element-from-array) | Hard | | 1706 | [Where Will the Ball Fall](https://leetcode.com/problems/where-will-the-ball-fall "球会落何处") | [Go](problems/where-will-the-ball-fall) | Medium | | 1705 | [Maximum Number of Eaten Apples](https://leetcode.com/problems/maximum-number-of-eaten-apples "吃苹果的最大数目") | [Go](problems/maximum-number-of-eaten-apples) | Medium | @@ -110,13 +127,13 @@ LeetCode Problems' Solutions | 1686 | [Stone Game VI](https://leetcode.com/problems/stone-game-vi "石子游戏 VI") | [Go](problems/stone-game-vi) | Medium | | 1685 | [Sum of Absolute Differences in a Sorted Array](https://leetcode.com/problems/sum-of-absolute-differences-in-a-sorted-array "有序数组中差绝对值之和") | [Go](problems/sum-of-absolute-differences-in-a-sorted-array) | Medium | | 1684 | [Count the Number of Consistent Strings](https://leetcode.com/problems/count-the-number-of-consistent-strings "统计一致字符串的数目") | [Go](problems/count-the-number-of-consistent-strings) | Easy | -| 1683 | [Invalid Tweets](https://leetcode.com/problems/invalid-tweets) 🔒 | [MySQL](problems/invalid-tweets) | Easy | +| 1683 | [Invalid Tweets](https://leetcode.com/problems/invalid-tweets "无效的推文") 🔒 | [MySQL](problems/invalid-tweets) | Easy | | 1682 | [Longest Palindromic Subsequence II](https://leetcode.com/problems/longest-palindromic-subsequence-ii "最长回文子序列 II") 🔒 | [Go](problems/longest-palindromic-subsequence-ii) | Medium | | 1681 | [Minimum Incompatibility](https://leetcode.com/problems/minimum-incompatibility "最小不兼容性") | [Go](problems/minimum-incompatibility) | Hard | | 1680 | [Concatenation of Consecutive Binary Numbers](https://leetcode.com/problems/concatenation-of-consecutive-binary-numbers "连接连续二进制数字") | [Go](problems/concatenation-of-consecutive-binary-numbers) | Medium | | 1679 | [Max Number of K-Sum Pairs](https://leetcode.com/problems/max-number-of-k-sum-pairs "K 和数对的最大数目") | [Go](problems/max-number-of-k-sum-pairs) | Medium | | 1678 | [Goal Parser Interpretation](https://leetcode.com/problems/goal-parser-interpretation "设计 Goal 解析器") | [Go](problems/goal-parser-interpretation) | Easy | -| 1677 | [Product's Worth Over Invoices](https://leetcode.com/problems/products-worth-over-invoices) 🔒 | [MySQL](problems/products-worth-over-invoices) | Easy | +| 1677 | [Product's Worth Over Invoices](https://leetcode.com/problems/products-worth-over-invoices "发票中的产品金额") 🔒 | [MySQL](problems/products-worth-over-invoices) | Easy | | 1676 | [Lowest Common Ancestor of a Binary Tree IV](https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-tree-iv "二叉树的最近公共祖先 IV") 🔒 | [Go](problems/lowest-common-ancestor-of-a-binary-tree-iv) | Medium | | 1675 | [Minimize Deviation in Array](https://leetcode.com/problems/minimize-deviation-in-array "数组的最小偏移量") | [Go](problems/minimize-deviation-in-array) | Hard | | 1674 | [Minimum Moves to Make Array Complementary](https://leetcode.com/problems/minimum-moves-to-make-array-complementary "使数组互补的最少操作次数") | [Go](problems/minimum-moves-to-make-array-complementary) | Medium | @@ -132,7 +149,7 @@ LeetCode Problems' Solutions | 1664 | [Ways to Make a Fair Array](https://leetcode.com/problems/ways-to-make-a-fair-array "生成平衡数组的方案数") | [Go](problems/ways-to-make-a-fair-array) | Medium | | 1663 | [Smallest String With A Given Numeric Value](https://leetcode.com/problems/smallest-string-with-a-given-numeric-value "具有给定数值的最小字符串") | [Go](problems/smallest-string-with-a-given-numeric-value) | Medium | | 1662 | [Check If Two String Arrays are Equivalent](https://leetcode.com/problems/check-if-two-string-arrays-are-equivalent "检查两个字符串数组是否相等") | [Go](problems/check-if-two-string-arrays-are-equivalent) | Easy | -| 1661 | [Average Time of Process per Machine](https://leetcode.com/problems/average-time-of-process-per-machine) 🔒 | [MySQL](problems/average-time-of-process-per-machine) | Easy | +| 1661 | [Average Time of Process per Machine](https://leetcode.com/problems/average-time-of-process-per-machine "每台机器的进程平均运行时间") 🔒 | [MySQL](problems/average-time-of-process-per-machine) | Easy | | 1660 | [Correct a Binary Tree](https://leetcode.com/problems/correct-a-binary-tree "纠正二叉树") 🔒 | [Go](problems/correct-a-binary-tree) | Medium | | 1659 | [Maximize Grid Happiness](https://leetcode.com/problems/maximize-grid-happiness "最大化网格幸福感") | [Go](problems/maximize-grid-happiness) | Hard | | 1658 | [Minimum Operations to Reduce X to Zero](https://leetcode.com/problems/minimum-operations-to-reduce-x-to-zero "将 x 减到 0 的最小操作数") | [Go](problems/minimum-operations-to-reduce-x-to-zero) | Medium | @@ -356,7 +373,7 @@ LeetCode Problems' Solutions | 1440 | [Evaluate Boolean Expression](https://leetcode.com/problems/evaluate-boolean-expression "计算布尔表达式的值") 🔒 | [MySQL](problems/evaluate-boolean-expression) | Medium | | 1439 | [Find the Kth Smallest Sum of a Matrix With Sorted Rows](https://leetcode.com/problems/find-the-kth-smallest-sum-of-a-matrix-with-sorted-rows "有序矩阵中的第 k 个最小数组和") | [Go](problems/find-the-kth-smallest-sum-of-a-matrix-with-sorted-rows) | Hard | | 1438 | [Longest Continuous Subarray With Absolute Diff Less Than or Equal to Limit](https://leetcode.com/problems/longest-continuous-subarray-with-absolute-diff-less-than-or-equal-to-limit "绝对差不超过限制的最长连续子数组") | [Go](problems/longest-continuous-subarray-with-absolute-diff-less-than-or-equal-to-limit) | Medium | -| 1437 | [Check If All 1's Are at Least Length K Places Away](https://leetcode.com/problems/check-if-all-1s-are-at-least-length-k-places-away "是否所有 1 都至少相隔 k 个元素") | [Go](problems/check-if-all-1s-are-at-least-length-k-places-away) | Medium | +| 1437 | [Check If All 1's Are at Least Length K Places Away](https://leetcode.com/problems/check-if-all-1s-are-at-least-length-k-places-away "是否所有 1 都至少相隔 k 个元素") | [Go](problems/check-if-all-1s-are-at-least-length-k-places-away) | Easy | | 1436 | [Destination City](https://leetcode.com/problems/destination-city "旅行终点站") | [Go](problems/destination-city) | Easy | | 1435 | [Create a Session Bar Chart](https://leetcode.com/problems/create-a-session-bar-chart "制作会话柱状图") 🔒 | [MySQL](problems/create-a-session-bar-chart) | Easy | | 1434 | [Number of Ways to Wear Different Hats to Each Other](https://leetcode.com/problems/number-of-ways-to-wear-different-hats-to-each-other "每个人戴不同帽子的方案数") | [Go](problems/number-of-ways-to-wear-different-hats-to-each-other) | Hard | @@ -556,7 +573,7 @@ LeetCode Problems' Solutions | 1240 | [Tiling a Rectangle with the Fewest Squares](https://leetcode.com/problems/tiling-a-rectangle-with-the-fewest-squares "铺瓷砖") | [Go](problems/tiling-a-rectangle-with-the-fewest-squares) | Hard | | 1239 | [Maximum Length of a Concatenated String with Unique Characters](https://leetcode.com/problems/maximum-length-of-a-concatenated-string-with-unique-characters "串联字符串的最大长度") | [Go](problems/maximum-length-of-a-concatenated-string-with-unique-characters) | Medium | | 1238 | [Circular Permutation in Binary Representation](https://leetcode.com/problems/circular-permutation-in-binary-representation "循环码排列") | [Go](problems/circular-permutation-in-binary-representation) | Medium | -| 1237 | [Find Positive Integer Solution for a Given Equation](https://leetcode.com/problems/find-positive-integer-solution-for-a-given-equation "找出给定方程的正整数解") | [Go](problems/find-positive-integer-solution-for-a-given-equation) | Easy | +| 1237 | [Find Positive Integer Solution for a Given Equation](https://leetcode.com/problems/find-positive-integer-solution-for-a-given-equation "找出给定方程的正整数解") | [Go](problems/find-positive-integer-solution-for-a-given-equation) | Medium | | 1236 | [Web Crawler](https://leetcode.com/problems/web-crawler "网络爬虫") 🔒 | [Go](problems/web-crawler) | Medium | | 1235 | [Maximum Profit in Job Scheduling](https://leetcode.com/problems/maximum-profit-in-job-scheduling "规划兼职工作") | [Go](problems/maximum-profit-in-job-scheduling) | Hard | | 1234 | [Replace the Substring for Balanced String](https://leetcode.com/problems/replace-the-substring-for-balanced-string "替换子串得到平衡字符串") | [Go](problems/replace-the-substring-for-balanced-string) | Medium | @@ -570,7 +587,7 @@ LeetCode Problems' Solutions | 1226 | [The Dining Philosophers](https://leetcode.com/problems/the-dining-philosophers "哲学家进餐") | [Go](problems/the-dining-philosophers) | Medium | | 1225 | [Report Contiguous Dates](https://leetcode.com/problems/report-contiguous-dates "报告系统状态的连续日期") 🔒 | [MySQL](problems/report-contiguous-dates) | Hard | | 1224 | [Maximum Equal Frequency](https://leetcode.com/problems/maximum-equal-frequency "最大相等频率") | [Go](problems/maximum-equal-frequency) | Hard | -| 1223 | [Dice Roll Simulation](https://leetcode.com/problems/dice-roll-simulation "掷骰子模拟") | [Go](problems/dice-roll-simulation) | Medium | +| 1223 | [Dice Roll Simulation](https://leetcode.com/problems/dice-roll-simulation "掷骰子模拟") | [Go](problems/dice-roll-simulation) | Hard | | 1222 | [Queens That Can Attack the King](https://leetcode.com/problems/queens-that-can-attack-the-king "可以攻击国王的皇后") | [Go](problems/queens-that-can-attack-the-king) | Medium | | 1221 | [Split a String in Balanced Strings](https://leetcode.com/problems/split-a-string-in-balanced-strings "分割平衡字符串") | [Go](problems/split-a-string-in-balanced-strings) | Easy | | 1220 | [Count Vowels Permutation](https://leetcode.com/problems/count-vowels-permutation "统计元音字母序列的数目") | [Go](problems/count-vowels-permutation) | Hard | diff --git a/problems/array-of-doubled-pairs/README.md b/problems/array-of-doubled-pairs/README.md index bc6c763d4..9385c0569 100644 --- a/problems/array-of-doubled-pairs/README.md +++ b/problems/array-of-doubled-pairs/README.md @@ -11,36 +11,27 @@ ## [954. Array of Doubled Pairs (Medium)](https://leetcode.com/problems/array-of-doubled-pairs "二倍数对数组") -

Given an array of integers A with even length, return true if and only if it is possible to reorder it such that A[2 * i + 1] = 2 * A[2 * i] for every 0 <= i < len(A) / 2.

- -
-
-
-
    -
-
-
-
+

Given an array of integers arr of even length, return true if and only if it is possible to reorder it such that arr[2 * i + 1] = 2 * arr[2 * i] for every 0 <= i < len(arr) / 2.

 

Example 1:

-Input: A = [3,1,3,6]
+Input: arr = [3,1,3,6]
 Output: false
 

Example 2:

-Input: A = [2,1,2,6]
+Input: arr = [2,1,2,6]
 Output: false
 

Example 3:

-Input: A = [4,-2,2,-4]
+Input: arr = [4,-2,2,-4]
 Output: true
 Explanation: We can take two groups, [-2,-4] and [2,4] to form [-2,-4,2,4] or [2,4,-2,-4].
 
@@ -48,7 +39,7 @@

Example 4:

-Input: A = [1,2,4,16,8,4]
+Input: arr = [1,2,4,16,8,4]
 Output: false
 
@@ -56,9 +47,9 @@

Constraints:

### Related Topics diff --git a/problems/asteroid-collision/README.md b/problems/asteroid-collision/README.md index 03edf127a..220b6f4e5 100644 --- a/problems/asteroid-collision/README.md +++ b/problems/asteroid-collision/README.md @@ -23,7 +23,7 @@
 Input: asteroids = [5,10,-5]
 Output: [5,10]
-Explanation: The 10 and -5 collide resulting in 10.  The 5 and 10 never collide.
+Explanation: The 10 and -5 collide resulting in 10. The 5 and 10 never collide.
 

Example 2:

@@ -54,7 +54,7 @@

Constraints:

diff --git a/problems/average-time-of-process-per-machine/README.md b/problems/average-time-of-process-per-machine/README.md index bf492a5da..f2f9aa0bc 100644 --- a/problems/average-time-of-process-per-machine/README.md +++ b/problems/average-time-of-process-per-machine/README.md @@ -9,6 +9,6 @@                  [Next >](../check-if-two-string-arrays-are-equivalent "Check If Two String Arrays are Equivalent") -## [1661. Average Time of Process per Machine (Easy)](https://leetcode.com/problems/average-time-of-process-per-machine "") +## [1661. Average Time of Process per Machine (Easy)](https://leetcode.com/problems/average-time-of-process-per-machine "每台机器的进程平均运行时间") diff --git a/problems/best-time-to-buy-and-sell-stock/README.md b/problems/best-time-to-buy-and-sell-stock/README.md index 0c951ccd2..119db2613 100644 --- a/problems/best-time-to-buy-and-sell-stock/README.md +++ b/problems/best-time-to-buy-and-sell-stock/README.md @@ -11,29 +11,38 @@ ## [121. Best Time to Buy and Sell Stock (Easy)](https://leetcode.com/problems/best-time-to-buy-and-sell-stock "买卖股票的最佳时机") -

Say you have an array for which the ith element is the price of a given stock on day i.

+

You are given an array prices where prices[i] is the price of a given stock on the ith day.

-

If you were only permitted to complete at most one transaction (i.e., buy one and sell one share of the stock), design an algorithm to find the maximum profit.

+

You want to maximize your profit by choosing a single day to buy one stock and choosing a different day in the future to sell that stock.

-

Note that you cannot sell a stock before you buy one.

+

Return the maximum profit you can achieve from this transaction. If you cannot achieve any profit, return 0.

+

 

Example 1:

-Input: [7,1,5,3,6,4]
+Input: prices = [7,1,5,3,6,4]
 Output: 5
 Explanation: Buy on day 2 (price = 1) and sell on day 5 (price = 6), profit = 6-1 = 5.
-             Not 7-1 = 6, as selling price needs to be larger than buying price.
+Note that buying on day 2 and selling on day 1 is not allowed because you must buy before you sell.
 

Example 2:

-Input: [7,6,4,3,1]
+Input: prices = [7,6,4,3,1]
 Output: 0
-Explanation: In this case, no transaction is done, i.e. max profit = 0.
+Explanation: In this case, no transactions are done and the max profit = 0.
 
+

 

+

Constraints:

+ + + ### Related Topics [[Array](../../tag/array/README.md)] [[Dynamic Programming](../../tag/dynamic-programming/README.md)] diff --git a/problems/binary-tree-maximum-path-sum/README.md b/problems/binary-tree-maximum-path-sum/README.md index e0d877648..e77db851b 100644 --- a/problems/binary-tree-maximum-path-sum/README.md +++ b/problems/binary-tree-maximum-path-sum/README.md @@ -11,9 +11,11 @@ ## [124. Binary Tree Maximum Path Sum (Hard)](https://leetcode.com/problems/binary-tree-maximum-path-sum "二叉树中的最大路径和") -

Given the root of a binary tree, return the maximum path sum.

+

A path in a binary tree is a sequence of nodes where each pair of adjacent nodes in the sequence has an edge connecting them. A node can only appear in the sequence at most once. Note that the path does not need to pass through the root.

-

For this problem, a path is defined as any node sequence from some starting node to any node in the tree along the parent-child connections. The path must contain at least one node and does not need to go through the root.

+

The path sum of a path is the sum of the node's values in the path.

+ +

Given the root of a binary tree, return the maximum path sum of any path.

 

Example 1:

@@ -21,6 +23,7 @@
 Input: root = [1,2,3]
 Output: 6
+Explanation: The optimal path is 2 -> 1 -> 3 with a path sum of 2 + 1 + 3 = 6.
 

Example 2:

@@ -28,6 +31,7 @@
 Input: root = [-10,9,20,null,null,15,7]
 Output: 42
+Explanation: The optimal path is 15 -> 20 -> 7 with a path sum of 15 + 20 + 7 = 42.
 

 

diff --git a/problems/binary-tree-preorder-traversal/README.md b/problems/binary-tree-preorder-traversal/README.md index 725ba549c..e3638d691 100644 --- a/problems/binary-tree-preorder-traversal/README.md +++ b/problems/binary-tree-preorder-traversal/README.md @@ -58,12 +58,7 @@

 

- -

Follow up:

- -

Recursive solution is trivial, could you do it iteratively?

- -

 

+

Follow up: Recursive solution is trivial, could you do it iteratively?

### Related Topics [[Stack](../../tag/stack/README.md)] diff --git a/problems/boats-to-save-people/README.md b/problems/boats-to-save-people/README.md index 80af1ce36..0c7d5be79 100644 --- a/problems/boats-to-save-people/README.md +++ b/problems/boats-to-save-people/README.md @@ -11,49 +11,42 @@ ## [881. Boats to Save People (Medium)](https://leetcode.com/problems/boats-to-save-people "救生艇") -

The i-th person has weight people[i], and each boat can carry a maximum weight of limit.

+

You are given an array people where people[i] is the weight of the ith person, and an infinite number of boats where each boat can carry a maximum weight of limit. Each boat carries at most two people at the same time, provided the sum of the weight of those people is at most limit.

-

Each boat carries at most 2 people at the same time, provided the sum of the weight of those people is at most limit.

- -

Return the minimum number of boats to carry every given person.  (It is guaranteed each person can be carried by a boat.)

+

Return the minimum number of boats to carry every given person.

 

- -

Example 1:

-Input: people = [1,2], limit = 3
-Output: 1
-Explanation: 1 boat (1, 2)
+Input: people = [1,2], limit = 3
+Output: 1
+Explanation: 1 boat (1, 2)
 
-

Example 2:

-Input: people = [3,2,2,1], limit = 3
-Output: 3
-Explanation: 3 boats (1, 2), (2) and (3)
+Input: people = [3,2,2,1], limit = 3
+Output: 3
+Explanation: 3 boats (1, 2), (2) and (3)
 
-

Example 3:

-Input: people = [3,5,3,4], limit = 5
-Output: 4
-Explanation: 4 boats (3), (3), (4), (5)
+Input: people = [3,5,3,4], limit = 5 +Output: 4 +Explanation: 4 boats (3), (3), (4), (5) + -

Note:

+

 

+

Constraints:

    -
  • 1 <= people.length <= 50000
  • -
  • 1 <= people[i] <= limit <= 30000
  • +
  • 1 <= people.length <= 5 * 104
  • +
  • 1 <= people[i] <= limit <= 3 * 104
-
-
-
### Related Topics [[Greedy](../../tag/greedy/README.md)] diff --git a/problems/building-boxes/README.md b/problems/building-boxes/README.md new file mode 100644 index 000000000..f9ca91771 --- /dev/null +++ b/problems/building-boxes/README.md @@ -0,0 +1,76 @@ + + + + + + + +[< Previous](../find-kth-largest-xor-coordinate-value "Find Kth Largest XOR Coordinate Value") +                 +[Next >](../find-distance-in-a-binary-tree "Find Distance in a Binary Tree") + +## [1739. Building Boxes (Hard)](https://leetcode.com/problems/building-boxes "放置盒子") + +

You have a cubic storeroom where the width, length, and height of the room are all equal to n units. You are asked to place n boxes in this room where each box is a cube of unit side length. There are however some rules to placing the boxes:

+ + + +

Given an integer n, return the minimum possible number of boxes touching the floor.

+ +

 

+

Example 1:

+ +

+ +
+Input: n = 3
+Output: 3
+Explanation: The figure above is for the placement of the three boxes.
+These boxes are placed in the corner of the room, where the corner is on the left side.
+
+ +

Example 2:

+ +

+ +
+Input: n = 4
+Output: 3
+Explanation: The figure above is for the placement of the four boxes.
+These boxes are placed in the corner of the room, where the corner is on the left side.
+
+ +

Example 3:

+ +

+ +
+Input: n = 10
+Output: 6
+Explanation: The figure above is for the placement of the ten boxes.
+These boxes are placed in the corner of the room, where the corner is on the back side.
+ +

 

+

Constraints:

+ + + +### Related Topics + [[Math](../../tag/math/README.md)] + [[Binary Search](../../tag/binary-search/README.md)] + +### Hints +
+Hint 1 +Suppose We can put m boxes on the floor, within all the ways to put the boxes, what’s the maximum number of boxes we can put in? +
+ +
+Hint 2 +The first box should always start in the corner +
diff --git a/problems/burst-balloons/README.md b/problems/burst-balloons/README.md index 1ea3f3b9f..01d0681b5 100644 --- a/problems/burst-balloons/README.md +++ b/problems/burst-balloons/README.md @@ -13,7 +13,7 @@

You are given n balloons, indexed from 0 to n - 1. Each balloon is painted with a number on it represented by an array nums. You are asked to burst all the balloons.

-

If you burst the ith balloon, you will get nums[left] * nums[i] * nums[right] coins. Here left and right are adjacent indices of i. After the burst, the left and right then becomes adjacent.

+

If you burst the ith balloon, you will get nums[i - 1] * nums[i] * nums[i + 1] coins. If i - 1 or i + 1 goes out of bounds of the array, then treat it as if there is a balloon with a 1 painted on it.

Return the maximum coins you can collect by bursting the balloons wisely.

@@ -23,8 +23,8 @@
 Input: nums = [3,1,5,8]
 Output: 167
-Explanation:
-nums = [3,1,5,8] --> [3,5,8] --> [3,8] --> [8] --> []
+Explanation:
+nums = [3,1,5,8] --> [3,5,8] --> [3,8] --> [8] --> []
 coins =  3*1*5    +   3*5*8   +  1*3*8  + 1*8*1 = 167

Example 2:

diff --git a/problems/capacity-to-ship-packages-within-d-days/README.md b/problems/capacity-to-ship-packages-within-d-days/README.md index e311fa320..6832bd250 100644 --- a/problems/capacity-to-ship-packages-within-d-days/README.md +++ b/problems/capacity-to-ship-packages-within-d-days/README.md @@ -13,35 +13,32 @@

A conveyor belt has packages that must be shipped from one port to another within D days.

-

The i-th package on the conveyor belt has a weight of weights[i].  Each day, we load the ship with packages on the conveyor belt (in the order given by weights). We may not load more weight than the maximum weight capacity of the ship.

+

The ith package on the conveyor belt has a weight of weights[i]. Each day, we load the ship with packages on the conveyor belt (in the order given by weights). We may not load more weight than the maximum weight capacity of the ship.

Return the least weight capacity of the ship that will result in all the packages on the conveyor belt being shipped within D days.

 

-

Example 1:

-Input: weights = [1,2,3,4,5,6,7,8,9,10], D = 5
-Output: 15
-Explanation: 
-A ship capacity of 15 is the minimum to ship all the packages in 5 days like this:
+Input: weights = [1,2,3,4,5,6,7,8,9,10], D = 5
+Output: 15
+Explanation: A ship capacity of 15 is the minimum to ship all the packages in 5 days like this:
 1st day: 1, 2, 3, 4, 5
 2nd day: 6, 7
 3rd day: 8
 4th day: 9
 5th day: 10
 
-Note that the cargo must be shipped in the order given, so using a ship of capacity 14 and splitting the packages into parts like (2, 3, 4, 5), (1, 6, 7), (8), (9), (10) is not allowed. 
+Note that the cargo must be shipped in the order given, so using a ship of capacity 14 and splitting the packages into parts like (2, 3, 4, 5), (1, 6, 7), (8), (9), (10) is not allowed.
 

Example 2:

-Input: weights = [3,2,2,4,1,4], D = 3
-Output: 6
-Explanation: 
-A ship capacity of 6 is the minimum to ship all the packages in 3 days like this:
+Input: weights = [3,2,2,4,1,4], D = 3
+Output: 6
+Explanation: A ship capacity of 6 is the minimum to ship all the packages in 3 days like this:
 1st day: 3, 2
 2nd day: 2, 4
 3rd day: 1, 4
@@ -50,9 +47,9 @@ A ship capacity of 6 is the minimum to ship all the packages in 3 days like this
 

Example 3:

-Input: weights = [1,2,3,1,1], D = 4
-Output: 3
-Explanation: 
+Input: weights = [1,2,3,1,1], D = 4
+Output: 3
+Explanation:
 1st day: 1
 2nd day: 2
 3rd day: 3
@@ -63,7 +60,7 @@ A ship capacity of 6 is the minimum to ship all the packages in 3 days like this
 

Constraints:

    -
  • 1 <= D <= weights.length <= 50000
  • +
  • 1 <= D <= weights.length <= 5 * 104
  • 1 <= weights[i] <= 500
diff --git a/problems/cat-and-mouse-ii/README.md b/problems/cat-and-mouse-ii/README.md new file mode 100644 index 000000000..711a42f2b --- /dev/null +++ b/problems/cat-and-mouse-ii/README.md @@ -0,0 +1,107 @@ + + + + + + + +[< Previous](../largest-submatrix-with-rearrangements "Largest Submatrix With Rearrangements") +                 +[Next >](../find-followers-count "Find Followers Count") + +## [1728. Cat and Mouse II (Hard)](https://leetcode.com/problems/cat-and-mouse-ii "猫和老鼠 II") + +

A game is played by a cat and a mouse named Cat and Mouse.

+ +

The environment is represented by a grid of size rows x cols, where each element is a wall, floor, player (Cat, Mouse), or food.

+ +
    +
  • Players are represented by the characters 'C'(Cat),'M'(Mouse).
  • +
  • Floors are represented by the character '.' and can be walked on.
  • +
  • Walls are represented by the character '#' and cannot be walked on.
  • +
  • Food is represented by the character 'F' and can be walked on.
  • +
  • There is only one of each character 'C', 'M', and 'F' in grid.
  • +
+ +

Mouse and Cat play according to the following rules:

+ +
    +
  • Mouse moves first, then they take turns to move.
  • +
  • During each turn, Cat and Mouse can jump in one of the four directions (left, right, up, down). They cannot jump over the wall nor outside of the grid.
  • +
  • catJump, mouseJump are the maximum lengths Cat and Mouse can jump at a time, respectively. Cat and Mouse can jump less than the maximum length.
  • +
  • Staying in the same position is allowed.
  • +
  • Mouse can jump over Cat.
  • +
+ +

The game can end in 4 ways:

+ +
    +
  • If Cat occupies the same position as Mouse, Cat wins.
  • +
  • If Cat reaches the food first, Cat wins.
  • +
  • If Mouse reaches the food first, Mouse wins.
  • +
  • If Mouse cannot get to the food within 1000 turns, Cat wins.
  • +
+ +

Given a rows x cols matrix grid and two integers catJump and mouseJump, return true if Mouse can win the game if both Cat and Mouse play optimally, otherwise return false.

+ +

 

+

Example 1:

+ +

+ +
+Input: grid = ["####F","#C...","M...."], catJump = 1, mouseJump = 2
+Output: true
+Explanation: Cat cannot catch Mouse on its turn nor can it get the food before Mouse.
+
+ +

Example 2:

+ +

+ +
+Input: grid = ["M.C...F"], catJump = 1, mouseJump = 4
+Output: true
+
+ +

Example 3:

+ +
+Input: grid = ["M.C...F"], catJump = 1, mouseJump = 3
+Output: false
+
+ +

Example 4:

+ +
+Input: grid = ["C...#","...#F","....#","M...."], catJump = 2, mouseJump = 5
+Output: false
+
+ +

Example 5:

+ +
+Input: grid = [".M...","..#..","#..#.","C#.#.","...#F"], catJump = 3, mouseJump = 1
+Output: true
+
+ +

 

+

Constraints:

+ +
    +
  • rows == grid.length
  • +
  • cols = grid[i].length
  • +
  • 1 <= rows, cols <= 8
  • +
  • grid[i][j] consist only of characters 'C', 'M', 'F', '.', and '#'.
  • +
  • There is only one of each character 'C', 'M', and 'F' in grid.
  • +
  • 1 <= catJump, mouseJump <= 8
  • +
+ +### Related Topics + [[Dynamic Programming](../../tag/dynamic-programming/README.md)] + +### Hints +
+Hint 1 +Try working backward: consider all trivial states you know to be winning or losing, and work backward to determine which other states can be labeled as winning or losing. +
diff --git a/problems/change-minimum-characters-to-satisfy-one-of-three-conditions/README.md b/problems/change-minimum-characters-to-satisfy-one-of-three-conditions/README.md new file mode 100644 index 000000000..0c02683b5 --- /dev/null +++ b/problems/change-minimum-characters-to-satisfy-one-of-three-conditions/README.md @@ -0,0 +1,68 @@ + + + + + + + +[< Previous](../latest-time-by-replacing-hidden-digits "Latest Time by Replacing Hidden Digits") +                 +[Next >](../find-kth-largest-xor-coordinate-value "Find Kth Largest XOR Coordinate Value") + +## [1737. Change Minimum Characters to Satisfy One of Three Conditions (Medium)](https://leetcode.com/problems/change-minimum-characters-to-satisfy-one-of-three-conditions "满足三条件之一需改变的最少字符数") + +

You are given two strings a and b that consist of lowercase letters. In one operation, you can change any character in a or b to any lowercase letter.

+ +

Your goal is to satisfy one of the following three conditions:

+ +
    +
  • Every letter in a is strictly less than every letter in b in the alphabet.
  • +
  • Every letter in b is strictly less than every letter in a in the alphabet.
  • +
  • Both a and b consist of only one distinct letter.
  • +
+ +

Return the minimum number of operations needed to achieve your goal.

+ +

 

+

Example 1:

+ +
+Input: a = "aba", b = "caa"
+Output: 2
+Explanation: Consider the best way to make each condition true:
+1) Change b to "ccc" in 2 operations, then every letter in a is less than every letter in b.
+2) Change a to "bbb" and b to "aaa" in 3 operations, then every letter in b is less than every letter in a.
+3) Change a to "aaa" and b to "aaa" in 2 operations, then a and b consist of one distinct letter.
+The best way was done in 2 operations (either condition 1 or condition 3).
+
+ +

Example 2:

+ +
+Input: a = "dabadd", b = "cda"
+Output: 3
+Explanation: The best way is to make condition 1 true by changing b to "eee".
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= a.length, b.length <= 105
  • +
  • a and b consist only of lowercase letters.
  • +
+ +### Related Topics + [[Greedy](../../tag/greedy/README.md)] + [[String](../../tag/string/README.md)] + +### Hints +
+Hint 1 +Iterate on each letter in the alphabet, and check the smallest number of operations needed to make it one of the following: the largest letter in a and smaller than the smallest one in b, vice versa, or let a and b consist only of this letter. +
+ +
+Hint 2 +For the first 2 conditions, take care that you can only change characters to lowercase letters, so you can't make 'z' the smallest letter in one of the strings or 'a' the largest letter in one of them. +
diff --git a/problems/check-if-all-1s-are-at-least-length-k-places-away/README.md b/problems/check-if-all-1s-are-at-least-length-k-places-away/README.md index b285ea86e..7e7b72d6f 100644 --- a/problems/check-if-all-1s-are-at-least-length-k-places-away/README.md +++ b/problems/check-if-all-1s-are-at-least-length-k-places-away/README.md @@ -9,7 +9,7 @@                  [Next >](../longest-continuous-subarray-with-absolute-diff-less-than-or-equal-to-limit "Longest Continuous Subarray With Absolute Diff Less Than or Equal to Limit") -## [1437. Check If All 1's Are at Least Length K Places Away (Medium)](https://leetcode.com/problems/check-if-all-1s-are-at-least-length-k-places-away "是否所有 1 都至少相隔 k 个元素") +## [1437. Check If All 1's Are at Least Length K Places Away (Easy)](https://leetcode.com/problems/check-if-all-1s-are-at-least-length-k-places-away "是否所有 1 都至少相隔 k 个元素")

Given an array nums of 0s and 1s and an integer k, return True if all 1's are at least k places away from each other, otherwise return False.

@@ -51,9 +51,9 @@

Constraints:

    -
  • 1 <= nums.length <= 10^5
  • +
  • 1 <= nums.length <= 105
  • 0 <= k <= nums.length
  • -
  • nums[i] is 0 or 1
  • +
  • nums[i] is 0 or 1
### Related Topics diff --git a/problems/checking-existence-of-edge-length-limited-paths-ii/README.md b/problems/checking-existence-of-edge-length-limited-paths-ii/README.md new file mode 100644 index 000000000..159005616 --- /dev/null +++ b/problems/checking-existence-of-edge-length-limited-paths-ii/README.md @@ -0,0 +1,35 @@ + + + + + + + +[< Previous](../find-minimum-time-to-finish-all-jobs "Find Minimum Time to Finish All Jobs") +                 +[Next >](../number-of-rectangles-that-can-form-the-largest-square "Number Of Rectangles That Can Form The Largest Square") + +## [1724. Checking Existence of Edge Length Limited Paths II (Hard)](https://leetcode.com/problems/checking-existence-of-edge-length-limited-paths-ii "") + + + +### Related Topics + [[Union Find](../../tag/union-find/README.md)] + [[Graph](../../tag/graph/README.md)] + [[Dynamic Programming](../../tag/dynamic-programming/README.md)] + +### Hints +
+Hint 1 +Find the minimum spanning tree of the given graph. +
+ +
+Hint 2 +Root the tree in an arbitrary node and calculate the maximum weight of the edge from each node to the chosen root. +
+ +
+Hint 3 +To answer a query, find the lca between the two nodes, and find the maximum weight from each of the query nodes to their lca and compare it to the given limit. +
diff --git a/problems/coin-path/README.md b/problems/coin-path/README.md index d230d792b..4bc08d280 100644 --- a/problems/coin-path/README.md +++ b/problems/coin-path/README.md @@ -52,5 +52,5 @@ [[Dynamic Programming](../../tag/dynamic-programming/README.md)] ### Similar Questions - 1. [House Robber](../house-robber) (Easy) + 1. [House Robber](../house-robber) (Medium) 1. [House Robber II](../house-robber-ii) (Medium) diff --git a/problems/compare-strings-by-frequency-of-the-smallest-character/README.md b/problems/compare-strings-by-frequency-of-the-smallest-character/README.md index c17b913ac..6741914e6 100644 --- a/problems/compare-strings-by-frequency-of-the-smallest-character/README.md +++ b/problems/compare-strings-by-frequency-of-the-smallest-character/README.md @@ -9,11 +9,13 @@                  [Next >](../remove-zero-sum-consecutive-nodes-from-linked-list "Remove Zero Sum Consecutive Nodes from Linked List") -## [1170. Compare Strings by Frequency of the Smallest Character (Easy)](https://leetcode.com/problems/compare-strings-by-frequency-of-the-smallest-character "比较字符串最小字母出现频次") +## [1170. Compare Strings by Frequency of the Smallest Character (Medium)](https://leetcode.com/problems/compare-strings-by-frequency-of-the-smallest-character "比较字符串最小字母出现频次") -

Let's define a function f(s) over a non-empty string s, which calculates the frequency of the smallest character in s. For example, if s = "dcce" then f(s) = 2 because the smallest character is "c" and its frequency is 2.

+

Let the function f(s) be the frequency of the lexicographically smallest character in a non-empty string s. For example, if s = "dcce" then f(s) = 2 because the lexicographically smallest character is 'c', which has a frequency of 2.

-

Now, given string arrays queries and words, return an integer array answer, where each answer[i] is the number of words such that f(queries[i]) < f(W), where W is a word in words.

+

You are given an array of strings words and another array of query strings queries. For each query queries[i], count the number of words in words such that f(queries[i]) < f(W) for each W in words.

+ +

Return an integer array answer, where each answer[i] is the answer to the ith query.

 

Example 1:

@@ -39,12 +41,13 @@
  • 1 <= queries.length <= 2000
  • 1 <= words.length <= 2000
  • 1 <= queries[i].length, words[i].length <= 10
  • -
  • queries[i][j], words[i][j] are English lowercase letters.
  • +
  • queries[i][j], words[i][j] consist of lowercase English letters.
  • ### Related Topics [[Array](../../tag/array/README.md)] [[String](../../tag/string/README.md)] + [[Binary Search](../../tag/binary-search/README.md)] ### Hints
    diff --git a/problems/count-complete-tree-nodes/README.md b/problems/count-complete-tree-nodes/README.md index bcc3eedbc..ae2d96bfb 100644 --- a/problems/count-complete-tree-nodes/README.md +++ b/problems/count-complete-tree-nodes/README.md @@ -11,24 +11,43 @@ ## [222. Count Complete Tree Nodes (Medium)](https://leetcode.com/problems/count-complete-tree-nodes "完全二叉树的节点个数") -

    Given a complete binary tree, count the number of nodes.

    +

    Given the root of a complete binary tree, return the number of the nodes in the tree.

    -

    Note:

    +

    According to Wikipedia, every level, except possibly the last, is completely filled in a complete binary tree, and all nodes in the last level are as far left as possible. It can have between 1 and 2h nodes inclusive at the last level h.

    -

    Definition of a complete binary tree from Wikipedia:
    -In a complete binary tree every level, except possibly the last, is completely filled, and all nodes in the last level are as far left as possible. It can have between 1 and 2h nodes inclusive at the last level h.

    +

     

    +

    Example 1:

    + +
    +Input: root = [1,2,3,4,5,6]
    +Output: 6
    +
    + +

    Example 2:

    + +
    +Input: root = []
    +Output: 0
    +
    -

    Example:

    +

    Example 3:

    -Input: 
    -    1
    -   / \
    -  2   3
    - / \  /
    -4  5 6
    -
    -Output: 6
    +Input: root = [1] +Output: 1 +
    + +

     

    +

    Constraints:

    + + + +

     

    +Follow up: Traversing the tree to count the number of nodes in the tree is an easy solution but with O(n) complexity. Could you find a faster algorithm? ### Related Topics [[Tree](../../tag/tree/README.md)] diff --git a/problems/count-number-of-teams/README.md b/problems/count-number-of-teams/README.md index 6f7670f95..81fb7b979 100644 --- a/problems/count-number-of-teams/README.md +++ b/problems/count-number-of-teams/README.md @@ -11,13 +11,13 @@ ## [1395. Count Number of Teams (Medium)](https://leetcode.com/problems/count-number-of-teams "统计作战单位数") -

    There are n soldiers standing in a line. Each soldier is assigned a unique rating value.

    +

    There are n soldiers standing in a line. Each soldier is assigned a unique rating value.

    -

    You have to form a team of 3 soldiers amongst them under the following rules:

    +

    You have to form a team of 3 soldiers amongst them under the following rules:

    Return the number of teams you can form given the conditions. (soldiers can be part of multiple teams).

    @@ -51,8 +51,9 @@ ### Related Topics diff --git a/problems/count-of-smaller-numbers-after-self/README.md b/problems/count-of-smaller-numbers-after-self/README.md index 57edfdf13..d6731f452 100644 --- a/problems/count-of-smaller-numbers-after-self/README.md +++ b/problems/count-of-smaller-numbers-after-self/README.md @@ -11,7 +11,7 @@ ## [315. Count of Smaller Numbers After Self (Hard)](https://leetcode.com/problems/count-of-smaller-numbers-after-self "计算右侧小于当前元素的个数") -

    You are given an integer array nums and you have to return a new counts array. The counts array has the property where counts[i] is the number of smaller elements to the right of nums[i].

    +

    You are given an integer array nums and you have to return a new counts array. The counts array has the property where counts[i] is the number of smaller elements to the right of nums[i].

     

    Example 1:

    @@ -26,12 +26,26 @@ To the right of 6 there is 1 smaller element (1). To the right of 1 there is 0 smaller element.
    +

    Example 2:

    + +
    +Input: nums = [-1]
    +Output: [0]
    +
    + +

    Example 3:

    + +
    +Input: nums = [-1,-1]
    +Output: [0,0]
    +
    +

     

    Constraints:

    ### Related Topics diff --git a/problems/count-ways-to-make-array-with-product/README.md b/problems/count-ways-to-make-array-with-product/README.md new file mode 100644 index 000000000..c2db3b12b --- /dev/null +++ b/problems/count-ways-to-make-array-with-product/README.md @@ -0,0 +1,57 @@ + + + + + + + +[< Previous](../decode-xored-permutation "Decode XORed Permutation") +                 +[Next >](../latest-time-by-replacing-hidden-digits "Latest Time by Replacing Hidden Digits") + +## [1735. Count Ways to Make Array With Product (Hard)](https://leetcode.com/problems/count-ways-to-make-array-with-product "生成乘积数组的方案数") + +

    You are given a 2D integer array, queries. For each queries[i], where queries[i] = [ni, ki], find the number of different ways you can place positive integers into an array of size ni such that the product of the integers is ki. As the number of ways may be too large, the answer to the ith query is the number of ways modulo 109 + 7.

    + +

    Return an integer array answer where answer.length == queries.length, and answer[i] is the answer to the ith query.

    + +

     

    +

    Example 1:

    + +
    +Input: queries = [[2,6],[5,1],[73,660]]
    +Output: [4,1,50734910]
    +Explanation: Each query is independent.
    +[2,6]: There are 4 ways to fill an array of size 2 that multiply to 6: [1,6], [2,3], [3,2], [6,1].
    +[5,1]: There is 1 way to fill an array of size 5 that multiply to 1: [1,1,1,1,1].
    +[73,660]: There are 1050734917 ways to fill an array of size 73 that multiply to 660. 1050734917 modulo 109 + 7 = 50734910.
    +
    + +

    Example 2:

    + +
    +Input: queries = [[1,1],[2,2],[3,3],[4,4],[5,5]]
    +Output: [1,2,3,10,5]
    +
    + +

     

    +

    Constraints:

    + + + +### Related Topics + [[Math](../../tag/math/README.md)] + +### Hints +
    +Hint 1 +Prime-factorize ki and count how many ways you can distribute the primes among the ni positions. +
    + +
    +Hint 2 +After prime factorizing ki, suppose there are x amount of prime factor. There are (x + n - 1) choose (n - 1) ways to distribute the x prime factors into k positions, allowing repetitions. +
    diff --git a/problems/decode-ways/README.md b/problems/decode-ways/README.md index eda25cb55..58e0cc639 100644 --- a/problems/decode-ways/README.md +++ b/problems/decode-ways/README.md @@ -55,8 +55,9 @@ Since there is no character, there are no valid ways to decode this since all di

    Example 4:

    -Input: s = "1"
    -Output: 1
    +Input: s = "06"
    +Output: 0
    +Explanation: "06" cannot be mapped to "F" because the zero at the beginning of the string can't make a valid character. 
     

     

    diff --git a/problems/decode-xored-permutation/README.md b/problems/decode-xored-permutation/README.md new file mode 100644 index 000000000..ca6f80de0 --- /dev/null +++ b/problems/decode-xored-permutation/README.md @@ -0,0 +1,67 @@ + + + + + + + +[< Previous](../minimum-number-of-people-to-teach "Minimum Number of People to Teach") +                 +[Next >](../count-ways-to-make-array-with-product "Count Ways to Make Array With Product") + +## [1734. Decode XORed Permutation (Medium)](https://leetcode.com/problems/decode-xored-permutation "解码异或后的排列") + +

    There is an integer array perm that is a permutation of the first n positive integers, where n is always odd.

    + +

    It was encoded into another integer array encoded of length n - 1, such that encoded[i] = perm[i] XOR perm[i + 1]. For example, if perm = [1,3,2], then encoded = [2,1].

    + +

    Given the encoded array, return the original array perm. It is guaranteed that the answer exists and is unique.

    + +

     

    +

    Example 1:

    + +
    +Input: encoded = [3,1]
    +Output: [1,2,3]
    +Explanation: If perm = [1,2,3], then encoded = [1 XOR 2,2 XOR 3] = [3,1]
    +
    + +

    Example 2:

    + +
    +Input: encoded = [6,5,4,6]
    +Output: [2,4,1,5,3]
    +
    + +

     

    +

    Constraints:

    + + + +### Related Topics + [[Bit Manipulation](../../tag/bit-manipulation/README.md)] + +### Hints +
    +Hint 1 +Compute the XOR of the numbers between 1 and n, and think about how it can be used. Let it be x. +
    + +
    +Hint 2 +Think why n is odd. +
    + +
    +Hint 3 +perm[0] = x XOR encoded[1] XOR encoded[3] XOR encoded[5] ... +
    + +
    +Hint 4 +perm[i] = perm[i-1] XOR encoded[i-1] +
    diff --git a/problems/delete-and-earn/README.md b/problems/delete-and-earn/README.md index 517fcfb44..d6912c94a 100644 --- a/problems/delete-and-earn/README.md +++ b/problems/delete-and-earn/README.md @@ -55,7 +55,7 @@ Then, delete 3 again to earn 3 points, and 3 again to earn 3 points. [[Dynamic Programming](../../tag/dynamic-programming/README.md)] ### Similar Questions - 1. [House Robber](../house-robber) (Easy) + 1. [House Robber](../house-robber) (Medium) ### Hints
    diff --git a/problems/design-add-and-search-words-data-structure/README.md b/problems/design-add-and-search-words-data-structure/README.md index e2687212e..29acf55cb 100644 --- a/problems/design-add-and-search-words-data-structure/README.md +++ b/problems/design-add-and-search-words-data-structure/README.md @@ -53,6 +53,7 @@ wordDictionary.search("b.."); // return True ### Related Topics + [[Depth-first Search](../../tag/depth-first-search/README.md)] [[Design](../../tag/design/README.md)] [[Trie](../../tag/trie/README.md)] [[Backtracking](../../tag/backtracking/README.md)] diff --git a/problems/design-hashset/README.md b/problems/design-hashset/README.md index 4af6db33c..c073a3e73 100644 --- a/problems/design-hashset/README.md +++ b/problems/design-hashset/README.md @@ -11,40 +11,48 @@ ## [705. Design HashSet (Easy)](https://leetcode.com/problems/design-hashset "设计哈希集合") -

    Design a HashSet without using any built-in hash table libraries.

    +

    Design a HashSet without using any built-in hash table libraries.

    -

    To be specific, your design should include these functions:

    +

    Implement MyHashSet class:

    -


    -Example:

    +

     

    +

    Example 1:

    -MyHashSet hashSet = new MyHashSet();
    -hashSet.add(1);         
    -hashSet.add(2);         
    -hashSet.contains(1);    // returns true
    -hashSet.contains(3);    // returns false (not found)
    -hashSet.add(2);          
    -hashSet.contains(2);    // returns true
    -hashSet.remove(2);          
    -hashSet.contains(2);    // returns false (already removed)
    -
    - -


    -Note:

    +Input +["MyHashSet", "add", "add", "contains", "contains", "add", "contains", "remove", "contains"] +[[], [1], [2], [1], [3], [2], [2], [2], [2]] +Output +[null, null, null, true, false, null, true, null, false] + +Explanation +MyHashSet myHashSet = new MyHashSet(); +myHashSet.add(1); // set = [1] +myHashSet.add(2); // set = [1, 2] +myHashSet.contains(1); // return True +myHashSet.contains(3); // return False, (not found) +myHashSet.add(2); // set = [1, 2] +myHashSet.contains(2); // return True +myHashSet.remove(2); // set = [1] +myHashSet.contains(2); // return False, (already removed) + +

     

    +

    Constraints:

    +

     

    +Follow up: Could you solve the problem without using the built-in HashSet library? + ### Related Topics [[Design](../../tag/design/README.md)] [[Hash Table](../../tag/hash-table/README.md)] diff --git a/problems/divide-array-in-sets-of-k-consecutive-numbers/README.md b/problems/divide-array-in-sets-of-k-consecutive-numbers/README.md index b5867e953..1f1029eef 100644 --- a/problems/divide-array-in-sets-of-k-consecutive-numbers/README.md +++ b/problems/divide-array-in-sets-of-k-consecutive-numbers/README.md @@ -11,8 +11,8 @@ ## [1296. Divide Array in Sets of K Consecutive Numbers (Medium)](https://leetcode.com/problems/divide-array-in-sets-of-k-consecutive-numbers "划分数组为连续数字的集合") -

    Given an array of integers nums and a positive integer k, find whether it's possible to divide this array into sets of k consecutive numbers
    -Return True if its possible otherwise return False.

    +

    Given an array of integers nums and a positive integer k, find whether it's possible to divide this array into sets of k consecutive numbers
    +Return True if it is possible. Otherwise, return False.

     

    Example 1:

    @@ -50,11 +50,12 @@ Return True if its possible otherwi

    Constraints:

    -Note: This question is the same as 846: https://leetcode.com/problems/hand-of-straights/ + +

     

    +Note: This question is the same as 846: https://leetcode.com/problems/hand-of-straights/ ### Related Topics [[Greedy](../../tag/greedy/README.md)] diff --git a/problems/find-a-value-of-a-mysterious-function-closest-to-target/README.md b/problems/find-a-value-of-a-mysterious-function-closest-to-target/README.md index 34f152d87..5b6881e14 100644 --- a/problems/find-a-value-of-a-mysterious-function-closest-to-target/README.md +++ b/problems/find-a-value-of-a-mysterious-function-closest-to-target/README.md @@ -13,11 +13,11 @@

    -

    Winston was given the above mysterious function func. He has an integer array arr and an integer target and he wants to find the values l and r that make the value |func(arr, l, r) - target| minimum possible.

    +

    Winston was given the above mysterious function func. He has an integer array arr and an integer target and he wants to find the values l and r that make the value |func(arr, l, r) - target| minimum possible.

    Return the minimum possible value of |func(arr, l, r) - target|.

    -

    Notice that func should be called with the values l and r where 0 <= l, r < arr.length.

    +

    Notice that func should be called with the values l and r where 0 <= l, r < arr.length.

     

    Example 1:

    @@ -47,9 +47,9 @@

    Constraints:

    ### Related Topics diff --git a/problems/find-distance-in-a-binary-tree/README.md b/problems/find-distance-in-a-binary-tree/README.md new file mode 100644 index 000000000..e0d51c19f --- /dev/null +++ b/problems/find-distance-in-a-binary-tree/README.md @@ -0,0 +1,30 @@ + + + + + + + +[< Previous](../building-boxes "Building Boxes") +                 +Next > + +## [1740. Find Distance in a Binary Tree (Easy)](https://leetcode.com/problems/find-distance-in-a-binary-tree "") + + + +### Related Topics + [[Tree](../../tag/tree/README.md)] + [[Depth-first Search](../../tag/depth-first-search/README.md)] + [[Breadth-first Search](../../tag/breadth-first-search/README.md)] + +### Hints +
    +Hint 1 +Get the LCA of p and q. +
    + +
    +Hint 2 +The answer is the sum of distances between p-LCA and q-LCA +
    diff --git a/problems/find-followers-count/README.md b/problems/find-followers-count/README.md new file mode 100644 index 000000000..52d82b032 --- /dev/null +++ b/problems/find-followers-count/README.md @@ -0,0 +1,14 @@ + + + + + + + +[< Previous](../cat-and-mouse-ii "Cat and Mouse II") +                 +[Next >](../shortest-path-to-get-food "Shortest Path to Get Food") + +## [1729. Find Followers Count (Easy)](https://leetcode.com/problems/find-followers-count "") + + diff --git a/problems/find-followers-count/mysql_schemas.sql b/problems/find-followers-count/mysql_schemas.sql new file mode 100644 index 000000000..dda0ddddf --- /dev/null +++ b/problems/find-followers-count/mysql_schemas.sql @@ -0,0 +1,6 @@ +Create table If Not Exists Followers(user_id int, follower_id int); +Truncate table Followers; +insert into Followers (user_id, follower_id) values ('0', '1'); +insert into Followers (user_id, follower_id) values ('1', '0'); +insert into Followers (user_id, follower_id) values ('2', '0'); +insert into Followers (user_id, follower_id) values ('2', '1'); diff --git a/problems/find-k-closest-elements/README.md b/problems/find-k-closest-elements/README.md index ab9557ab8..7a62a8d2a 100644 --- a/problems/find-k-closest-elements/README.md +++ b/problems/find-k-closest-elements/README.md @@ -11,7 +11,7 @@ ## [658. Find K Closest Elements (Medium)](https://leetcode.com/problems/find-k-closest-elements "找到 K 个最接近的元素") -

    Given a sorted integer array arr, two integers k and x, return the k closest integers to x in the array. The result should also be sorted in ascending order.

    +

    Given a sorted integer array arr, two integers k and x, return the k closest integers to x in the array. The result should also be sorted in ascending order.

    An integer a is closer to x than an integer b if:

    @@ -33,8 +33,9 @@ ### Related Topics diff --git a/problems/find-kth-largest-xor-coordinate-value/README.md b/problems/find-kth-largest-xor-coordinate-value/README.md new file mode 100644 index 000000000..9f4c9e140 --- /dev/null +++ b/problems/find-kth-largest-xor-coordinate-value/README.md @@ -0,0 +1,67 @@ + + + + + + + +[< Previous](../change-minimum-characters-to-satisfy-one-of-three-conditions "Change Minimum Characters to Satisfy One of Three Conditions") +                 +[Next >](../building-boxes "Building Boxes") + +## [1738. Find Kth Largest XOR Coordinate Value (Medium)](https://leetcode.com/problems/find-kth-largest-xor-coordinate-value "找出第 K 大的异或坐标值") + +

    You are given a 2D matrix of size m x n, consisting of non-negative integers. You are also given an integer k.

    + +

    The value of coordinate (a, b) of the matrix is the XOR of all matrix[i][j] where 0 <= i <= a < m and 0 <= j <= b < n (0-indexed).

    + +

    Find the kth largest value (1-indexed) of all the coordinates of matrix.

    + +

     

    +

    Example 1:

    + +
    +Input: matrix = [[5,2],[1,6]], k = 1
    +Output: 7
    +Explanation: The value of coordinate (0,1) is 5 XOR 2 = 7, which is the largest value.
    + +

    Example 2:

    + +
    +Input: matrix = [[5,2],[1,6]], k = 2
    +Output: 5
    +Explanation: The value of coordinate (0,0) is 5 = 5, which is the 2nd largest value.
    + +

    Example 3:

    + +
    +Input: matrix = [[5,2],[1,6]], k = 3
    +Output: 4
    +Explanation: The value of coordinate (1,0) is 5 XOR 1 = 4, which is the 3rd largest value.
    + +

    Example 4:

    + +
    +Input: matrix = [[5,2],[1,6]], k = 4
    +Output: 0
    +Explanation: The value of coordinate (1,1) is 5 XOR 2 XOR 1 XOR 6 = 0, which is the 4th largest value.
    + +

     

    +

    Constraints:

    + + + +### Related Topics + [[Array](../../tag/array/README.md)] + +### Hints +
    +Hint 1 +Use a 2D prefix sum to precalculate the xor-sum of the upper left submatrix. +
    diff --git a/problems/find-minimum-time-to-finish-all-jobs/README.md b/problems/find-minimum-time-to-finish-all-jobs/README.md index 4e1521129..03362e8ee 100644 --- a/problems/find-minimum-time-to-finish-all-jobs/README.md +++ b/problems/find-minimum-time-to-finish-all-jobs/README.md @@ -7,7 +7,7 @@ [< Previous](../minimize-hamming-distance-after-swap-operations "Minimize Hamming Distance After Swap Operations")                  -Next > +[Next >](../checking-existence-of-edge-length-limited-paths-ii "Checking Existence of Edge Length Limited Paths II") ## [1723. Find Minimum Time to Finish All Jobs (Hard)](https://leetcode.com/problems/find-minimum-time-to-finish-all-jobs "完成所有工作的最短时间") diff --git a/problems/find-positive-integer-solution-for-a-given-equation/README.md b/problems/find-positive-integer-solution-for-a-given-equation/README.md index f70520803..71355c3fa 100644 --- a/problems/find-positive-integer-solution-for-a-given-equation/README.md +++ b/problems/find-positive-integer-solution-for-a-given-equation/README.md @@ -9,30 +9,35 @@                  [Next >](../circular-permutation-in-binary-representation "Circular Permutation in Binary Representation") -## [1237. Find Positive Integer Solution for a Given Equation (Easy)](https://leetcode.com/problems/find-positive-integer-solution-for-a-given-equation "找出给定方程的正整数解") +## [1237. Find Positive Integer Solution for a Given Equation (Medium)](https://leetcode.com/problems/find-positive-integer-solution-for-a-given-equation "找出给定方程的正整数解") -

    Given a function  f(x, y) and a value z, return all positive integer pairs x and y where f(x,y) == z.

    +

    Given a callable function f(x, y) with a hidden formula and a value z, reverse engineer the formula and return all positive integer pairs x and y where f(x,y) == z. You may return the pairs in any order.

    -

    The function is constantly increasing, i.e.:

    +

    While the exact formula is hidden, the function is monotonically increasing, i.e.:

    -

    The function interface is defined like this: 

    +

    The function interface is defined like this:

     interface CustomFunction {
     public:
    -  // Returns positive integer f(x, y) for any given positive integer x and y.
    -  int f(int x, int y);
    +  // Returns some positive integer f(x, y) for two positive integers x and y based on a formula.
    +  int f(int x, int y);
     };
     
    -

    For custom testing purposes you're given an integer function_id and a target z as input, where function_id represent one function from an secret internal list, on the examples you'll know only two functions from the list.  

    +

    We will judge your solution as follows:

    -

    You may return the solutions in any order.

    +

     

    Example 1:

    @@ -40,14 +45,23 @@ public:
     Input: function_id = 1, z = 5
     Output: [[1,4],[2,3],[3,2],[4,1]]
    -Explanation: function_id = 1 means that f(x, y) = x + y
    +Explanation: The hidden formula for function_id = 1 is f(x, y) = x + y. +The following positive integer values of x and y make f(x, y) equal to 5: +x=1, y=4 -> f(1, 4) = 1 + 4 = 5. +x=2, y=3 -> f(2, 3) = 2 + 3 = 5. +x=3, y=2 -> f(3, 2) = 3 + 2 = 5. +x=4, y=1 -> f(4, 1) = 4 + 1 = 5. +

    Example 2:

     Input: function_id = 2, z = 5
     Output: [[1,5],[5,1]]
    -Explanation: function_id = 2 means that f(x, y) = x * y
    +Explanation: The hidden formula for function_id = 2 is f(x, y) = x * y.
    +The following positive integer values of x and y make f(x, y) equal to 5:
    +x=1, y=5 -> f(1, 5) = 1 * 5 = 5.
    +x=5, y=1 -> f(5, 1) = 5 * 1 = 5.
     

     

    @@ -56,8 +70,8 @@ public: ### Related Topics diff --git a/problems/find-the-highest-altitude/README.md b/problems/find-the-highest-altitude/README.md new file mode 100644 index 000000000..d2c7c859d --- /dev/null +++ b/problems/find-the-highest-altitude/README.md @@ -0,0 +1,56 @@ + + + + + + + +[< Previous](../the-number-of-employees-which-report-to-each-employee "The Number of Employees Which Report to Each Employee") +                 +[Next >](../minimum-number-of-people-to-teach "Minimum Number of People to Teach") + +## [1732. Find the Highest Altitude (Easy)](https://leetcode.com/problems/find-the-highest-altitude "找到最高海拔") + +

    There is a biker going on a road trip. The road trip consists of n + 1 points at different altitudes. The biker starts his trip on point 0 with altitude equal 0.

    + +

    You are given an integer array gain of length n where gain[i] is the net gain in altitude between points i​​​​​​ and i + 1 for all (0 <= i < n). Return the highest altitude of a point.

    + +

     

    +

    Example 1:

    + +
    +Input: gain = [-5,1,5,0,-7]
    +Output: 1
    +Explanation: The altitudes are [0,-5,-4,1,1,-6]. The highest is 1.
    +
    + +

    Example 2:

    + +
    +Input: gain = [-4,-3,-2,-1,4,3,2]
    +Output: 0
    +Explanation: The altitudes are [0,-4,-7,-9,-10,-6,-3,-1]. The highest is 0.
    +
    + +

     

    +

    Constraints:

    + + + +### Related Topics + [[Array](../../tag/array/README.md)] + +### Hints +
    +Hint 1 +Let's note that the altitude of an element is the sum of gains of all the elements behind it +
    + +
    +Hint 2 +Getting the altitudes can be done by getting the prefix sum array of the given array +
    diff --git a/problems/find-the-most-competitive-subsequence/README.md b/problems/find-the-most-competitive-subsequence/README.md index 6368432fa..1672cf137 100644 --- a/problems/find-the-most-competitive-subsequence/README.md +++ b/problems/find-the-most-competitive-subsequence/README.md @@ -44,7 +44,9 @@ ### Related Topics [[Stack](../../tag/stack/README.md)] + [[Heap](../../tag/heap/README.md)] [[Greedy](../../tag/greedy/README.md)] + [[Queue](../../tag/queue/README.md)] ### Hints
    diff --git a/problems/first-missing-positive/README.md b/problems/first-missing-positive/README.md index eccdb8f6f..6795f0dd1 100644 --- a/problems/first-missing-positive/README.md +++ b/problems/first-missing-positive/README.md @@ -11,9 +11,7 @@ ## [41. First Missing Positive (Hard)](https://leetcode.com/problems/first-missing-positive "缺失的第一个正数") -

    Given an unsorted integer array nums, find the smallest missing positive integer.

    - -

    Follow up: Could you implement an algorithm that runs in O(n) time and uses constant extra space.?

    +

    Given an unsorted integer array nums, find the smallest missing positive integer.

     

    Example 1:

    @@ -34,6 +32,9 @@
  • -231 <= nums[i] <= 231 - 1
  • +

     

    +

    Follow up: Could you implement an algorithm that runs in O(n) time and uses constant extra space?

    + ### Related Topics [[Array](../../tag/array/README.md)] diff --git a/problems/flatten-binary-tree-to-linked-list/README.md b/problems/flatten-binary-tree-to-linked-list/README.md index 52b53dbca..7613f1785 100644 --- a/problems/flatten-binary-tree-to-linked-list/README.md +++ b/problems/flatten-binary-tree-to-linked-list/README.md @@ -11,34 +11,46 @@ ## [114. Flatten Binary Tree to Linked List (Medium)](https://leetcode.com/problems/flatten-binary-tree-to-linked-list "二叉树展开为链表") -

    Given a binary tree, flatten it to a linked list in-place.

    +

    Given the root of a binary tree, flatten the tree into a "linked list":

    -

    For example, given the following tree:

    +
      +
    • The "linked list" should use the same TreeNode class where the right child pointer points to the next node in the list and the left child pointer is always null.
    • +
    • The "linked list" should be in the same order as a pre-order traversal of the binary tree.
    • +
    +

     

    +

    Example 1:

    +
    -    1
    -   / \
    -  2   5
    - / \   \
    -3   4   6
    +Input: root = [1,2,5,3,4,null,6]
    +Output: [1,null,2,null,3,null,4,null,5,null,6]
     
    -

    The flattened tree should look like:

    +

    Example 2:

    -1
    - \
    -  2
    -   \
    -    3
    -     \
    -      4
    -       \
    -        5
    -         \
    -          6
    +Input: root = []
    +Output: []
     
    +

    Example 3:

    + +
    +Input: root = [0]
    +Output: [0]
    +
    + +

     

    +

    Constraints:

    + +
      +
    • The number of nodes in the tree is in the range [0, 2000].
    • +
    • -100 <= Node.val <= 100
    • +
    + +

     

    +Follow up: Can you flatten the tree in-place (with O(1) extra space)? + ### Related Topics [[Tree](../../tag/tree/README.md)] [[Depth-first Search](../../tag/depth-first-search/README.md)] diff --git a/problems/gray-code/README.md b/problems/gray-code/README.md index d8f55d259..59eb1aaf0 100644 --- a/problems/gray-code/README.md +++ b/problems/gray-code/README.md @@ -46,7 +46,7 @@

    Constraints:

      -
    • 0 <= n <= 15
    • +
    • 1 <= n <= 16
    ### Related Topics diff --git a/problems/house-robber-ii/README.md b/problems/house-robber-ii/README.md index aaca6d143..08afb0147 100644 --- a/problems/house-robber-ii/README.md +++ b/problems/house-robber-ii/README.md @@ -52,7 +52,7 @@ Total amount you can rob = 1 + 3 = 4. [[Dynamic Programming](../../tag/dynamic-programming/README.md)] ### Similar Questions - 1. [House Robber](../house-robber) (Easy) + 1. [House Robber](../house-robber) (Medium) 1. [Paint House](../paint-house) (Medium) 1. [Paint Fence](../paint-fence) (Easy) 1. [House Robber III](../house-robber-iii) (Medium) diff --git a/problems/house-robber-iii/README.md b/problems/house-robber-iii/README.md index 55f2fe6f3..67ac3eb50 100644 --- a/problems/house-robber-iii/README.md +++ b/problems/house-robber-iii/README.md @@ -49,5 +49,5 @@ [[Depth-first Search](../../tag/depth-first-search/README.md)] ### Similar Questions - 1. [House Robber](../house-robber) (Easy) + 1. [House Robber](../house-robber) (Medium) 1. [House Robber II](../house-robber-ii) (Medium) diff --git a/problems/house-robber/README.md b/problems/house-robber/README.md index eec3c1ba5..004111de6 100644 --- a/problems/house-robber/README.md +++ b/problems/house-robber/README.md @@ -9,7 +9,7 @@                  [Next >](../binary-tree-right-side-view "Binary Tree Right Side View") -## [198. House Robber (Easy)](https://leetcode.com/problems/house-robber "打家劫舍") +## [198. House Robber (Medium)](https://leetcode.com/problems/house-robber "打家劫舍")

    You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping you from robbing each of them is that adjacent houses have security system connected and it will automatically contact the police if two adjacent houses were broken into on the same night.

    diff --git a/problems/insert-interval/README.md b/problems/insert-interval/README.md index 5aaeafc03..2937fb262 100644 --- a/problems/insert-interval/README.md +++ b/problems/insert-interval/README.md @@ -9,7 +9,7 @@                  [Next >](../length-of-last-word "Length of Last Word") -## [57. Insert Interval (Hard)](https://leetcode.com/problems/insert-interval "插入区间") +## [57. Insert Interval (Medium)](https://leetcode.com/problems/insert-interval "插入区间")

    Given a set of non-overlapping intervals, insert a new interval into the intervals (merge if necessary).

    diff --git a/problems/interval-list-intersections/README.md b/problems/interval-list-intersections/README.md index b394cb21e..52e4f92ad 100644 --- a/problems/interval-list-intersections/README.md +++ b/problems/interval-list-intersections/README.md @@ -11,34 +11,54 @@ ## [986. Interval List Intersections (Medium)](https://leetcode.com/problems/interval-list-intersections "区间列表的交集") -

    Given two lists of closed intervals, each list of intervals is pairwise disjoint and in sorted order.

    +

    You are given two lists of closed intervals, firstList and secondList, where firstList[i] = [starti, endi] and secondList[j] = [startj, endj]. Each list of intervals is pairwise disjoint and in sorted order.

    -

    Return the intersection of these two interval lists.

    +

    Return the intersection of these two interval lists.

    -

    (Formally, a closed interval [a, b] (with a <= b) denotes the set of real numbers x with a <= x <= b.  The intersection of two closed intervals is a set of real numbers that is either empty, or can be represented as a closed interval.  For example, the intersection of [1, 3] and [2, 4] is [2, 3].)

    +

    A closed interval [a, b] (with a < b) denotes the set of real numbers x with a <= x <= b.

    -
    -

     

    +

    The intersection of two closed intervals is a set of real numbers that are either empty or represented as a closed interval. For example, the intersection of [1, 3] and [2, 4] is [2, 3].

    +

     

    Example 1:

    + +
    +Input: firstList = [[0,2],[5,10],[13,23],[24,25]], secondList = [[1,5],[8,12],[15,24],[25,26]]
    +Output: [[1,2],[5,5],[8,10],[15,23],[24,24],[25,25]]
    +
    -

    +

    Example 2:

    -Input: A = [[0,2],[5,10],[13,23],[24,25]], B = [[1,5],[8,12],[15,24],[25,26]]
    -Output: [[1,2],[5,5],[8,10],[15,23],[24,24],[25,25]]
    +Input: firstList = [[1,3],[5,9]], secondList = []
    +Output: []
     
    -

     

    +

    Example 3:

    -

    Note:

    +
    +Input: firstList = [], secondList = [[4,8],[10,12]]
    +Output: []
    +
    + +

    Example 4:

    + +
    +Input: firstList = [[1,7]], secondList = [[3,10]]
    +Output: [[3,7]]
    +
    + +

     

    +

    Constraints:

    -
      -
    1. 0 <= A.length < 1000
    2. -
    3. 0 <= B.length < 1000
    4. -
    5. 0 <= A[i].start, A[i].end, B[i].start, B[i].end < 10^9
    6. -
    -
    +
      +
    • 0 <= firstList.length, secondList.length <= 1000
    • +
    • firstList.length + secondList.length >= 1
    • +
    • 0 <= starti < endi <= 109
    • +
    • endi < starti+1
    • +
    • 0 <= startj < endj <= 109
    • +
    • endj < startj+1
    • +
    ### Related Topics [[Two Pointers](../../tag/two-pointers/README.md)] diff --git a/problems/invalid-transactions/README.md b/problems/invalid-transactions/README.md index efdd20ee9..3e0997baf 100644 --- a/problems/invalid-transactions/README.md +++ b/problems/invalid-transactions/README.md @@ -11,16 +11,16 @@ ## [1169. Invalid Transactions (Medium)](https://leetcode.com/problems/invalid-transactions "查询无效交易") -

    A transaction is possibly invalid if:

    +

    A transaction is possibly invalid if:

      -
    • the amount exceeds $1000, or;
    • -
    • if it occurs within (and including) 60 minutes of another transaction with the same name in a different city.
    • +
    • the amount exceeds $1000, or;
    • +
    • if it occurs within (and including) 60 minutes of another transaction with the same name in a different city.
    -

    Each transaction string transactions[i] consists of comma separated values representing the name, time (in minutes), amount, and city of the transaction.

    +

    You are given an array of strings transaction where transactions[i] consists of comma-separated values representing the name, time (in minutes), amount, and city of the transaction.

    -

    Given a list of transactions, return a list of transactions that are possibly invalid.  You may return the answer in any order.

    +

    Return a list of transactions that are possibly invalid. You may return the answer in any order.

     

    Example 1:

    @@ -50,9 +50,9 @@
    • transactions.length <= 1000
    • Each transactions[i] takes the form "{name},{time},{amount},{city}"
    • -
    • Each {name} and {city} consist of lowercase English letters, and have lengths between 1 and 10.
    • -
    • Each {time} consist of digits, and represent an integer between 0 and 1000.
    • -
    • Each {amount} consist of digits, and represent an integer between 0 and 2000.
    • +
    • Each {name} and {city} consist of lowercase English letters, and have lengths between 1 and 10.
    • +
    • Each {time} consist of digits, and represent an integer between 0 and 1000.
    • +
    • Each {amount} consist of digits, and represent an integer between 0 and 2000.
    ### Related Topics diff --git a/problems/invalid-tweets/README.md b/problems/invalid-tweets/README.md index 121d0161d..501bb631a 100644 --- a/problems/invalid-tweets/README.md +++ b/problems/invalid-tweets/README.md @@ -9,6 +9,6 @@                  [Next >](../count-the-number-of-consistent-strings "Count the Number of Consistent Strings") -## [1683. Invalid Tweets (Easy)](https://leetcode.com/problems/invalid-tweets "") +## [1683. Invalid Tweets (Easy)](https://leetcode.com/problems/invalid-tweets "无效的推文") diff --git a/problems/k-concatenation-maximum-sum/README.md b/problems/k-concatenation-maximum-sum/README.md index 5e6b5ecb3..a42ff6462 100644 --- a/problems/k-concatenation-maximum-sum/README.md +++ b/problems/k-concatenation-maximum-sum/README.md @@ -11,13 +11,13 @@ ## [1191. K-Concatenation Maximum Sum (Medium)](https://leetcode.com/problems/k-concatenation-maximum-sum "K 次串联后最大子数组之和") -

    Given an integer array arr and an integer k, modify the array by repeating it k times.

    +

    Given an integer array arr and an integer k, modify the array by repeating it k times.

    -

    For example, if arr = [1, 2] and k = 3 then the modified array will be [1, 2, 1, 2, 1, 2].

    +

    For example, if arr = [1, 2] and k = 3 then the modified array will be [1, 2, 1, 2, 1, 2].

    -

    Return the maximum sub-array sum in the modified array. Note that the length of the sub-array can be 0 and its sum in that case is 0.

    +

    Return the maximum sub-array sum in the modified array. Note that the length of the sub-array can be 0 and its sum in that case is 0.

    -

    As the answer can be very large, return the answer modulo 10^9 + 7.

    +

    As the answer can be very large, return the answer modulo 109 + 7.

     

    Example 1:

    @@ -45,9 +45,9 @@

    Constraints:

      -
    • 1 <= arr.length <= 10^5
    • -
    • 1 <= k <= 10^5
    • -
    • -10^4 <= arr[i] <= 10^4
    • +
    • 1 <= arr.length <= 105
    • +
    • 1 <= k <= 105
    • +
    • -104 <= arr[i] <= 104
    ### Related Topics diff --git a/problems/k-th-smallest-prime-fraction/README.md b/problems/k-th-smallest-prime-fraction/README.md index e93afd957..2b091d885 100644 --- a/problems/k-th-smallest-prime-fraction/README.md +++ b/problems/k-th-smallest-prime-fraction/README.md @@ -11,29 +11,40 @@ ## [786. K-th Smallest Prime Fraction (Hard)](https://leetcode.com/problems/k-th-smallest-prime-fraction "第 K 个最小的素数分数") -

    A sorted list A contains 1, plus some number of primes.  Then, for every p < q in the list, we consider the fraction p/q.

    +

    You are given a sorted integer array arr containing 1 and prime numbers, where all the integers of arr are unique. You are also given an integer k.

    -

    What is the K-th smallest fraction considered?  Return your answer as an array of ints, where answer[0] = p and answer[1] = q.

    +

    For every i and j where 0 <= i < j < arr.length, we consider the fraction arr[i] / arr[j].

    + +

    Return the kth smallest fraction considered. Return your answer as an array of integers of size 2, where answer[0] == arr[i] and answer[1] == arr[j].

    + +

     

    +

    Example 1:

    -Examples:
    -Input: A = [1, 2, 3, 5], K = 3
    -Output: [2, 5]
    -Explanation:
    -The fractions to be considered in sorted order are:
    -1/5, 1/3, 2/5, 1/2, 3/5, 2/3.
    +Input: arr = [1,2,3,5], k = 3
    +Output: [2,5]
    +Explanation: The fractions to be considered in sorted order are:
    +1/5, 1/3, 2/5, 1/2, 3/5, and 2/3.
     The third fraction is 2/5.
    +
    -Input: A = [1, 7], K = 1 -Output: [1, 7] +

    Example 2:

    + +
    +Input: arr = [1,7], k = 1
    +Output: [1,7]
     
    -

    Note:

    +

     

    +

    Constraints:

      -
    • A will have length between 2 and 2000.
    • -
    • Each A[i] will be between 1 and 30000.
    • -
    • K will be between 1 and A.length * (A.length - 1) / 2.
    • +
    • 2 <= arr.length <= 1000
    • +
    • 1 <= arr[i] <= 3 * 104
    • +
    • arr[0] == 1
    • +
    • arr[i] is a prime number for i > 0.
    • +
    • All the numbers of arr are unique and sorted in strictly increasing order.
    • +
    • 1 <= k <= arr.length * (arr.length - 1) / 2
    ### Related Topics diff --git a/problems/keyboard-row/README.md b/problems/keyboard-row/README.md index 78137a474..140f7649a 100644 --- a/problems/keyboard-row/README.md +++ b/problems/keyboard-row/README.md @@ -11,28 +11,46 @@ ## [500. Keyboard Row (Easy)](https://leetcode.com/problems/keyboard-row "键盘行") -

    Given a List of words, return the words that can be typed using letters of alphabet on only one row's of American keyboard like the image below.

    +

    Given an array of strings words, return the words that can be typed using letters of the alphabet on only one row of American keyboard like the image below.

    +

    In the American keyboard:

    + +
      +
    • the first row consists of the characters "qwertyuiop",
    • +
    • the second row consists of the characters "asdfghjkl", and
    • +
    • the third row consists of the characters "zxcvbnm".
    • +
    +

     

    +

    Example 1:

    -

    -  +
    +Input: words = ["Hello","Alaska","Dad","Peace"]
    +Output: ["Alaska","Dad"]
    +
    -

    Example:

    +

    Example 2:

    -Input: ["Hello", "Alaska", "Dad", "Peace"]
    -Output: ["Alaska", "Dad"]
    +Input: words = ["omk"]
    +Output: []
     
    -

     

    +

    Example 3:

    -

    Note:

    +
    +Input: words = ["adsdf","sfd"]
    +Output: ["adsdf","sfd"]
    +
    + +

     

    +

    Constraints:

    -
      -
    1. You may use one character in the keyboard more than once.
    2. -
    3. You may assume the input string will only contain letters of alphabet.
    4. -
    +
      +
    • 1 <= words.length <= 20
    • +
    • 1 <= words[i].length <= 100
    • +
    • words[i] consists of English letters (both lowercase and uppercase). 
    • +
    ### Related Topics [[Hash Table](../../tag/hash-table/README.md)] diff --git a/problems/kth-smallest-element-in-a-bst/README.md b/problems/kth-smallest-element-in-a-bst/README.md index ccb774a3b..c36d3271e 100644 --- a/problems/kth-smallest-element-in-a-bst/README.md +++ b/problems/kth-smallest-element-in-a-bst/README.md @@ -11,46 +11,35 @@ ## [230. Kth Smallest Element in a BST (Medium)](https://leetcode.com/problems/kth-smallest-element-in-a-bst "二叉搜索树中第K小的元素") -

    Given a binary search tree, write a function kthSmallest to find the kth smallest element in it.

    +

    Given the root of a binary search tree, and an integer k, return the kth (1-indexed) smallest element in the tree.

     

    -

    Example 1:

    - +
     Input: root = [3,1,4,null,2], k = 1
    -   3
    -  / \
    - 1   4
    -  \
    -   2
    -Output: 1
    +Output: 1 +

    Example 2:

    - +
     Input: root = [5,3,6,2,4,null,null,1], k = 3
    -       5
    -      / \
    -     3   6
    -    / \
    -   2   4
    -  /
    - 1
     Output: 3
     
    -

    Follow up:
    -What if the BST is modified (insert/delete operations) often and you need to find the kth smallest frequently? How would you optimize the kthSmallest routine?

    -

     

    Constraints:

      -
    • The number of elements of the BST is between 1 to 10^4.
    • -
    • You may assume k is always valid, 1 ≤ k ≤ BST's total elements.
    • +
    • The number of nodes in the tree is n.
    • +
    • 1 <= k <= n <= 104
    • +
    • 0 <= Node.val <= 104
    +

     

    +Follow up: If the BST is modified often (i.e., we can do insert and delete operations) and you need to find the kth smallest frequently, how would you optimize? + ### Related Topics [[Tree](../../tag/tree/README.md)] [[Binary Search](../../tag/binary-search/README.md)] diff --git a/problems/largest-subarray-length-k/README.md b/problems/largest-subarray-length-k/README.md index f4c475c66..c4643ca22 100644 --- a/problems/largest-subarray-length-k/README.md +++ b/problems/largest-subarray-length-k/README.md @@ -9,7 +9,7 @@                  [Next >](../biggest-window-between-visits "Biggest Window Between Visits") -## [1708. Largest Subarray Length K (Easy)](https://leetcode.com/problems/largest-subarray-length-k "") +## [1708. Largest Subarray Length K (Easy)](https://leetcode.com/problems/largest-subarray-length-k "长度为 K 的最大子数组") diff --git a/problems/largest-submatrix-with-rearrangements/README.md b/problems/largest-submatrix-with-rearrangements/README.md new file mode 100644 index 000000000..0a91dc32b --- /dev/null +++ b/problems/largest-submatrix-with-rearrangements/README.md @@ -0,0 +1,78 @@ + + + + + + + +[< Previous](../tuple-with-same-product "Tuple with Same Product") +                 +[Next >](../cat-and-mouse-ii "Cat and Mouse II") + +## [1727. Largest Submatrix With Rearrangements (Medium)](https://leetcode.com/problems/largest-submatrix-with-rearrangements "重新排列后的最大子矩阵") + +

    You are given a binary matrix matrix of size m x n, and you are allowed to rearrange the columns of the matrix in any order.

    + +

    Return the area of the largest submatrix within matrix where every element of the submatrix is 1 after reordering the columns optimally.

    + +

     

    +

    Example 1:

    + +

    + +
    +Input: matrix = [[0,0,1],[1,1,1],[1,0,1]]
    +Output: 4
    +Explanation: You can rearrange the columns as shown above.
    +The largest submatrix of 1s, in bold, has an area of 4.
    +
    + +

    Example 2:

    + +

    + +
    +Input: matrix = [[1,0,1,0,1]]
    +Output: 3
    +Explanation: You can rearrange the columns as shown above.
    +The largest submatrix of 1s, in bold, has an area of 3.
    +
    + +

    Example 3:

    + +
    +Input: matrix = [[1,1,0],[1,0,1]]
    +Output: 2
    +Explanation: Notice that you must rearrange entire columns, and there is no way to make a submatrix of 1s larger than an area of 2.
    + +

    Example 4:

    + +
    +Input: matrix = [[0,0],[0,0]]
    +Output: 0
    +Explanation: As there are no 1s, no submatrix of 1s can be formed and the area is 0.
    + +

     

    +

    Constraints:

    + +
      +
    • m == matrix.length
    • +
    • n == matrix[i].length
    • +
    • 1 <= m * n <= 105
    • +
    • matrix[i][j] is 0 or 1.
    • +
    + +### Related Topics + [[Greedy](../../tag/greedy/README.md)] + [[Sort](../../tag/sort/README.md)] + +### Hints +
    +Hint 1 +For each column, find the number of consecutive ones ending at each position. +
    + +
    +Hint 2 +For each row, sort the cumulative ones in non-increasing order and "fit" the largest submatrix. +
    diff --git a/problems/latest-time-by-replacing-hidden-digits/README.md b/problems/latest-time-by-replacing-hidden-digits/README.md new file mode 100644 index 000000000..518bb1569 --- /dev/null +++ b/problems/latest-time-by-replacing-hidden-digits/README.md @@ -0,0 +1,64 @@ + + + + + + + +[< Previous](../count-ways-to-make-array-with-product "Count Ways to Make Array With Product") +                 +[Next >](../change-minimum-characters-to-satisfy-one-of-three-conditions "Change Minimum Characters to Satisfy One of Three Conditions") + +## [1736. Latest Time by Replacing Hidden Digits (Easy)](https://leetcode.com/problems/latest-time-by-replacing-hidden-digits "替换隐藏数字得到的最晚时间") + +

    You are given a string time in the form of hh:mm, where some of the digits in the string are hidden (represented by ?).

    + +

    The valid times are those inclusively between 00:00 and 23:59.

    + +

    Return the latest valid time you can get from time by replacing the hidden digits.

    + +

     

    +

    Example 1:

    + +
    +Input: time = "2?:?0"
    +Output: "23:50"
    +Explanation: The latest hour beginning with the digit '2' is 23 and the latest minute ending with the digit '0' is 50.
    +
    + +

    Example 2:

    + +
    +Input: time = "0?:3?"
    +Output: "09:39"
    +
    + +

    Example 3:

    + +
    +Input: time = "1?:22"
    +Output: "19:22"
    +
    + +

     

    +

    Constraints:

    + +
      +
    • time is in the format hh:mm.
    • +
    • It is guaranteed that you can produce a valid time from the given string.
    • +
    + +### Related Topics + [[Greedy](../../tag/greedy/README.md)] + [[String](../../tag/string/README.md)] + +### Hints +
    +Hint 1 +Trying out all possible solutions from biggest to smallest would fit in the time limit. +
    + +
    +Hint 2 +To check if the solution is okay, you need to find out if it's valid and matches every character +
    diff --git a/problems/lfu-cache/README.md b/problems/lfu-cache/README.md index f951ee4ce..94c9f70ca 100644 --- a/problems/lfu-cache/README.md +++ b/problems/lfu-cache/README.md @@ -11,17 +11,19 @@ ## [460. LFU Cache (Hard)](https://leetcode.com/problems/lfu-cache "LFU 缓存") -

    Design and implement a data structure for Least Frequently Used (LFU) cache.

    +

    Design and implement a data structure for a Least Frequently Used (LFU) cache.

    -

    Implement the LFUCache class:

    +

    Implement the LFUCache class:

    • LFUCache(int capacity) Initializes the object with the capacity of the data structure.
    • -
    • int get(int key) Gets the value of the key if the key exists in the cache. Otherwise, returns -1.
    • -
    • void put(int key, int value) Sets or inserts the value if the key is not already present. When the cache reaches its capacity, it should invalidate the least frequently used item before inserting a new item. For this problem, when there is a tie (i.e., two or more keys with the same frequency), the least recently used key would be evicted.
    • +
    • int get(int key) Gets the value of the key if the key exists in the cache. Otherwise, returns -1.
    • +
    • void put(int key, int value) Update the value of the key if present, or inserts the key if not already present. When the cache reaches its capacity, it should invalidate and remove the least frequently used key before inserting a new item. For this problem, when there is a tie (i.e., two or more keys with the same frequency), the least recently used key would be invalidated.
    -

    Notice that the number of times an item is used is the number of calls to the get and put functions for that item since it was inserted. This number is set to zero when the item is removed.

    +

    To determine the least frequently used key, a use counter is maintained for each key in the cache. The key with the smallest use counter is the least frequently used key.

    + +

    When a key is first inserted into the cache, its use counter is set to 1 (due to the put operation). The use counter for a key in the cache is incremented either a get or put operation is called on it.

     

    Example 1:

    @@ -34,24 +36,32 @@ [null, null, null, 1, null, -1, 3, null, -1, 3, 4] Explanation +// cnt(x) = the use counter for key x +// cache=[] will show the last used order for tiebreakers (leftmost element is most recent) LFUCache lfu = new LFUCache(2); -lfu.put(1, 1); -lfu.put(2, 2); +lfu.put(1, 1); // cache=[1,_], cnt(1)=1 +lfu.put(2, 2); // cache=[2,1], cnt(2)=1, cnt(1)=1 lfu.get(1); // return 1 -lfu.put(3, 3); // evicts key 2 + // cache=[1,2], cnt(2)=1, cnt(1)=2 +lfu.put(3, 3); // 2 is the LFU key because cnt(2)=1 is the smallest, invalidate 2. +  // cache=[3,1], cnt(3)=1, cnt(1)=2 lfu.get(2); // return -1 (not found) lfu.get(3); // return 3 -lfu.put(4, 4); // evicts key 1. + // cache=[3,1], cnt(3)=2, cnt(1)=2 +lfu.put(4, 4); // Both 1 and 3 have the same cnt, but 1 is LRU, invalidate 1. + // cache=[4,3], cnt(4)=1, cnt(3)=2 lfu.get(1); // return -1 (not found) lfu.get(3); // return 3 + // cache=[3,4], cnt(4)=1, cnt(3)=3 lfu.get(4); // return 4 + // cache=[3,4], cnt(4)=2, cnt(3)=3

     

    Constraints:

      -
    • 0 <= capacity, key, value <= 104
    • +
    • 0 <= capacity, key, value <= 104
    • At most 105 calls will be made to get and put.
    diff --git a/problems/longest-arithmetic-subsequence-of-given-difference/README.md b/problems/longest-arithmetic-subsequence-of-given-difference/README.md index 5dd08c02d..bfd9c439d 100644 --- a/problems/longest-arithmetic-subsequence-of-given-difference/README.md +++ b/problems/longest-arithmetic-subsequence-of-given-difference/README.md @@ -11,7 +11,9 @@ ## [1218. Longest Arithmetic Subsequence of Given Difference (Medium)](https://leetcode.com/problems/longest-arithmetic-subsequence-of-given-difference "最长定差子序列") -

    Given an integer array arr and an integer difference, return the length of the longest subsequence in arr which is an arithmetic sequence such that the difference between adjacent elements in the subsequence equals difference.

    +

    Given an integer array arr and an integer difference, return the length of the longest subsequence in arr which is an arithmetic sequence such that the difference between adjacent elements in the subsequence equals difference.

    + +

    A subsequence is a sequence that can be derived from arr by deleting some or no elements without changing the order of the remaining elements.

     

    Example 1:

    @@ -41,11 +43,12 @@

    Constraints:

      -
    • 1 <= arr.length <= 10^5
    • -
    • -10^4 <= arr[i], difference <= 10^4
    • +
    • 1 <= arr.length <= 105
    • +
    • -104 <= arr[i], difference <= 104
    ### Related Topics + [[Hash Table](../../tag/hash-table/README.md)] [[Math](../../tag/math/README.md)] [[Dynamic Programming](../../tag/dynamic-programming/README.md)] diff --git a/problems/longest-consecutive-sequence/README.md b/problems/longest-consecutive-sequence/README.md index bb9824cce..2c7ab18a4 100644 --- a/problems/longest-consecutive-sequence/README.md +++ b/problems/longest-consecutive-sequence/README.md @@ -13,8 +13,6 @@

    Given an unsorted array of integers nums, return the length of the longest consecutive elements sequence.

    -

    Follow up: Could you implement the O(n) solution? 

    -

     

    Example 1:

    @@ -39,6 +37,9 @@
  • -109 <= nums[i] <= 109
  • +

     

    +Follow up: Could you implement the O(n) solution? + ### Related Topics [[Union Find](../../tag/union-find/README.md)] [[Array](../../tag/array/README.md)] diff --git a/problems/longest-increasing-path-in-a-matrix/README.md b/problems/longest-increasing-path-in-a-matrix/README.md index 729dda6e6..c00d9c570 100644 --- a/problems/longest-increasing-path-in-a-matrix/README.md +++ b/problems/longest-increasing-path-in-a-matrix/README.md @@ -11,7 +11,7 @@ ## [329. Longest Increasing Path in a Matrix (Hard)](https://leetcode.com/problems/longest-increasing-path-in-a-matrix "矩阵中的最长递增路径") -

    Given an m x n matrix, return the length of the longest increasing path in matrix.

    +

    Given an m x n integers matrix, return the length of the longest increasing path in matrix.

    From each cell, you can either move in four directions: left, right, up, or down. You may not move diagonally or move outside the boundary (i.e., wrap-around is not allowed).

    @@ -25,7 +25,7 @@

    Example 2:

    - +
     Input: matrix = [[3,4,5],[3,2,6],[2,2,1]]
     Output: 4
    diff --git a/problems/maximum-level-sum-of-a-binary-tree/README.md b/problems/maximum-level-sum-of-a-binary-tree/README.md
    index 56f9074ac..caea5dfc4 100644
    --- a/problems/maximum-level-sum-of-a-binary-tree/README.md
    +++ b/problems/maximum-level-sum-of-a-binary-tree/README.md
    @@ -11,9 +11,9 @@
     
     ## [1161. Maximum Level Sum of a Binary Tree (Medium)](https://leetcode.com/problems/maximum-level-sum-of-a-binary-tree "最大层内元素和")
     
    -

    Given the root of a binary tree, the level of its root is 1, the level of its children is 2, and so on.

    +

    Given the root of a binary tree, the level of its root is 1, the level of its children is 2, and so on.

    -

    Return the smallest level X such that the sum of all the values of nodes at level X is maximal.

    +

    Return the smallest level x such that the sum of all the values of nodes at level x is maximal.

     

    Example 1:

    @@ -40,7 +40,7 @@ So we return the level with the maximum sum which is level 2.
    • The number of nodes in the tree is in the range [1, 104].
    • -
    • -105 <= Node.val <= 105
    • +
    • -105 <= Node.val <= 105
    ### Related Topics diff --git a/problems/maximum-number-of-visible-points/README.md b/problems/maximum-number-of-visible-points/README.md index 9dd342b88..4f0326cf0 100644 --- a/problems/maximum-number-of-visible-points/README.md +++ b/problems/maximum-number-of-visible-points/README.md @@ -13,7 +13,7 @@

    You are given an array points, an integer angle, and your location, where location = [posx, posy] and points[i] = [xi, yi] both denote integral coordinates on the X-Y plane.

    -

    Initially, you are facing directly east from your position. You cannot move from your position, but you can rotate. In other words, posx and posy cannot be changed. Your field of view in degrees is represented by angle, determining how wide you can see from any given view direction. Let d be the amount in degrees that you rotate counterclockwise. Then, your field of view is the inclusive range of angles [d - angle/2, d + angle/2].

    +

    Initially, you are facing directly east from your position. You cannot move from your position, but you can rotate. In other words, posx and posy cannot be changed. Your field of view in degrees is represented by angle, determining how wide you can see from any given view direction. Let d be the amount in degrees that you rotate counterclockwise. Then, your field of view is the inclusive range of angles [d - angle/2, d + angle/2].

    @@ -58,7 +58,7 @@

  • points[i].length == 2
  • location.length == 2
  • 0 <= angle < 360
  • -
  • 0 <= posx, posy, xi, yi <= 109
  • +
  • 0 <= posx, posy, xi, yi <= 100
  • ### Related Topics diff --git a/problems/maximum-product-subarray/README.md b/problems/maximum-product-subarray/README.md index f2ebe7fbf..9e981d397 100644 --- a/problems/maximum-product-subarray/README.md +++ b/problems/maximum-product-subarray/README.md @@ -34,7 +34,7 @@ ### Similar Questions 1. [Maximum Subarray](../maximum-subarray) (Easy) - 1. [House Robber](../house-robber) (Easy) + 1. [House Robber](../house-robber) (Medium) 1. [Product of Array Except Self](../product-of-array-except-self) (Medium) 1. [Maximum Product of Three Numbers](../maximum-product-of-three-numbers) (Easy) 1. [Subarray Product Less Than K](../subarray-product-less-than-k) (Medium) diff --git a/problems/meeting-scheduler/README.md b/problems/meeting-scheduler/README.md index 361377598..1bc07e1e8 100644 --- a/problems/meeting-scheduler/README.md +++ b/problems/meeting-scheduler/README.md @@ -47,6 +47,8 @@ ### Related Topics + [[Sort](../../tag/sort/README.md)] + [[Two Pointers](../../tag/two-pointers/README.md)] [[Line Sweep](../../tag/line-sweep/README.md)] ### Hints diff --git a/problems/merge-intervals/README.md b/problems/merge-intervals/README.md index ebfc285ad..364a16562 100644 --- a/problems/merge-intervals/README.md +++ b/problems/merge-intervals/README.md @@ -44,7 +44,7 @@ [[Array](../../tag/array/README.md)] ### Similar Questions - 1. [Insert Interval](../insert-interval) (Hard) + 1. [Insert Interval](../insert-interval) (Medium) 1. [Meeting Rooms](../meeting-rooms) (Easy) 1. [Meeting Rooms II](../meeting-rooms-ii) (Medium) 1. [Teemo Attacking](../teemo-attacking) (Medium) diff --git a/problems/merge-sorted-array/README.md b/problems/merge-sorted-array/README.md index be265a7c6..92c40344e 100644 --- a/problems/merge-sorted-array/README.md +++ b/problems/merge-sorted-array/README.md @@ -13,7 +13,7 @@

    Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array.

    -

    The number of elements initialized in nums1 and nums2 are m and n respectively. You may assume that nums1 has enough space (size that is equal to m + n) to hold additional elements from nums2.

    +

    The number of elements initialized in nums1 and nums2 are m and n respectively. You may assume that nums1 has a size equal to m + n such that it has enough space to hold additional elements from nums2.

     

    Example 1:

    @@ -27,10 +27,10 @@

    Constraints:

      -
    • 0 <= n, m <= 200
    • -
    • 1 <= n + m <= 200
    • nums1.length == m + n
    • nums2.length == n
    • +
    • 0 <= m, n <= 200
    • +
    • 1 <= m + n <= 200
    • -109 <= nums1[i], nums2[i] <= 109
    diff --git a/problems/minimize-malware-spread-ii/README.md b/problems/minimize-malware-spread-ii/README.md index 7c8751027..f150f2105 100644 --- a/problems/minimize-malware-spread-ii/README.md +++ b/problems/minimize-malware-spread-ii/README.md @@ -11,59 +11,41 @@ ## [928. Minimize Malware Spread II (Hard)](https://leetcode.com/problems/minimize-malware-spread-ii "尽量减少恶意软件的传播 II") -

    (This problem is the same as Minimize Malware Spread, with the differences bolded.)

    +

    You are given a network of n nodes represented as an n x n adjacency matrix graph, where the ith node is directly connected to the jth node if graph[i][j] == 1.

    -

    In a network of nodes, each node i is directly connected to another node j if and only if graph[i][j] = 1.

    +

    Some nodes initial are initially infected by malware. Whenever two nodes are directly connected, and at least one of those two nodes is infected by malware, both nodes will be infected by malware. This spread of malware will continue until no more nodes can be infected in this manner.

    -

    Some nodes initial are initially infected by malware.  Whenever two nodes are directly connected and at least one of those two nodes is infected by malware, both nodes will be infected by malware.  This spread of malware will continue until no more nodes can be infected in this manner.

    +

    Suppose M(initial) is the final number of nodes infected with malware in the entire network after the spread of malware stops.

    -

    Suppose M(initial) is the final number of nodes infected with malware in the entire network, after the spread of malware stops.

    +

    We will remove exactly one node from initial, completely removing it and any connections from this node to any other node.

    -

    We will remove one node from the initial list, completely removing it and any connections from this node to any other node.  Return the node that if removed, would minimize M(initial).  If multiple nodes could be removed to minimize M(initial), return such a node with the smallest index.

    +

    Return the node that, if removed, would minimize M(initial). If multiple nodes could be removed to minimize M(initial), return such a node with the smallest index.

     

    - -
      -
    - -

    Example 1:

    - -
    -Input: graph = [[1,1,0],[1,1,0],[0,0,1]], initial = [0,1]
    -Output: 0
    -
    - -
    -

    Example 2:

    - -
    -Input: graph = [[1,1,0],[1,1,1],[0,1,1]], initial = [0,1]
    -Output: 1
    +
    Input: graph = [[1,1,0],[1,1,0],[0,0,1]], initial = [0,1]
    +Output: 0
    +

    Example 2:

    +
    Input: graph = [[1,1,0],[1,1,1],[0,1,1]], initial = [0,1]
    +Output: 1
    +

    Example 3:

    +
    Input: graph = [[1,1,0,0],[1,1,1,0],[0,1,1,1],[0,0,1,1]], initial = [0,1]
    +Output: 1
     
    - -
    -

    Example 3:

    - -
    -Input: graph = [[1,1,0,0],[1,1,1,0],[0,1,1,1],[0,0,1,1]], initial = [0,1]
    -Output: 1
    -
    -

     

    - -

    Note:

    - -
      -
    1. 1 < graph.length = graph[0].length <= 300
    2. -
    3. 0 <= graph[i][j] == graph[j][i] <= 1
    4. -
    5. graph[i][i] = 1
    6. -
    7. 1 <= initial.length < graph.length
    8. -
    9. 0 <= initial[i] < graph.length
    10. -
    -
    -
    -
    +

    Constraints:

    + +
      +
    • n == graph.length
    • +
    • n == graph[i].length
    • +
    • 2 <= n <= 300
    • +
    • graph[i][j] is 0 or 1.
    • +
    • graph[i][j] == graph[j][i]
    • +
    • graph[i][i] == 1
    • +
    • 1 <= initial.length < n
    • +
    • 0 <= initial[i] <= n - 1
    • +
    • All the integers in initial are unique.
    • +
    ### Related Topics [[Depth-first Search](../../tag/depth-first-search/README.md)] diff --git a/problems/minimize-malware-spread/README.md b/problems/minimize-malware-spread/README.md index 7006bac65..b55400056 100644 --- a/problems/minimize-malware-spread/README.md +++ b/problems/minimize-malware-spread/README.md @@ -13,13 +13,13 @@

    You are given a network of n nodes represented as an n x n adjacency matrix graph, where the ith node is directly connected to the jth node if graph[i][j] == 1.

    -

    Some nodes initial are initially infected by malware. Whenever two nodes are directly connected and at least one of those two nodes is infected by malware, both nodes will be infected by malware. This spread of malware will continue until no more nodes can be infected in this manner.

    +

    Some nodes initial are initially infected by malware. Whenever two nodes are directly connected, and at least one of those two nodes is infected by malware, both nodes will be infected by malware. This spread of malware will continue until no more nodes can be infected in this manner.

    Suppose M(initial) is the final number of nodes infected with malware in the entire network after the spread of malware stops. We will remove exactly one node from initial.

    -

    Return the node that if removed, would minimize M(initial). If multiple nodes could be removed to minimize M(initial), return such a node with the smallest index.

    +

    Return the node that, if removed, would minimize M(initial). If multiple nodes could be removed to minimize M(initial), return such a node with the smallest index.

    -

    Note that if a node was removed from the initial list of infected nodes, it may still be infected later as a result of the malware spread.

    +

    Note that if a node was removed from the initial list of infected nodes, it might still be infected later due to the malware spread.

     

    Example 1:

    diff --git a/problems/minimum-number-of-people-to-teach/README.md b/problems/minimum-number-of-people-to-teach/README.md new file mode 100644 index 000000000..0da9d8daa --- /dev/null +++ b/problems/minimum-number-of-people-to-teach/README.md @@ -0,0 +1,71 @@ + + + + + + + +[< Previous](../find-the-highest-altitude "Find the Highest Altitude") +                 +[Next >](../decode-xored-permutation "Decode XORed Permutation") + +## [1733. Minimum Number of People to Teach (Medium)](https://leetcode.com/problems/minimum-number-of-people-to-teach "需要教语言的最少人数") + +

    On a social network consisting of m users and some friendships between users, two users can communicate with each other if they know a common language.

    + +

    You are given an integer n, an array languages, and an array friendships where:

    + +
      +
    • There are n languages numbered 1 through n,
    • +
    • languages[i] is the set of languages the i​​​​​​th​​​​ user knows, and
    • +
    • friendships[i] = [u​​​​​​i​​​, v​​​​​​i] denotes a friendship between the users u​​​​​​​​​​​i​​​​​ and vi.
    • +
    + +

    You can choose one language and teach it to some users so that all friends can communicate with each other. Return the minimum number of users you need to teach.

    +Note that friendships are not transitive, meaning if x is a friend of y and y is a friend of z, this doesn't guarantee that x is a friend of z. +

     

    +

    Example 1:

    + +
    +Input: n = 2, languages = [[1],[2],[1,2]], friendships = [[1,2],[1,3],[2,3]]
    +Output: 1
    +Explanation: You can either teach user 1 the second language or user 2 the first language.
    +
    + +

    Example 2:

    + +
    +Input: n = 3, languages = [[2],[1,3],[1,2],[3]], friendships = [[1,4],[1,2],[3,4],[2,3]]
    +Output: 2
    +Explanation: Teach the third language to users 1 and 3, yielding two users to teach.
    +
    + +

     

    +

    Constraints:

    + +
      +
    • 2 <= n <= 500
    • +
    • languages.length == m
    • +
    • 1 <= m <= 500
    • +
    • 1 <= languages[i].length <= n
    • +
    • 1 <= languages[i][j] <= n
    • +
    • 1 <= u​​​​​​i < v​​​​​​i <= languages.length
    • +
    • 1 <= friendships.length <= 500
    • +
    • All tuples (u​​​​​i, v​​​​​​i) are unique
    • +
    • languages[i] contains only unique values
    • +
    + +### Related Topics + [[Greedy](../../tag/greedy/README.md)] + [[Array](../../tag/array/README.md)] + +### Hints +
    +Hint 1 +You can just use brute force and find out for each language the number of users you need to teach +
    + +
    +Hint 2 +Note that a user can appear in multiple friendships but you need to teach that user only once +
    diff --git a/problems/minimum-operations-to-reduce-x-to-zero/README.md b/problems/minimum-operations-to-reduce-x-to-zero/README.md index 28215e19f..034a45d1d 100644 --- a/problems/minimum-operations-to-reduce-x-to-zero/README.md +++ b/problems/minimum-operations-to-reduce-x-to-zero/README.md @@ -52,14 +52,15 @@ [[Greedy](../../tag/greedy/README.md)] [[Two Pointers](../../tag/two-pointers/README.md)] [[Binary Search](../../tag/binary-search/README.md)] + [[Sliding Window](../../tag/sliding-window/README.md)] ### Hints
    Hint 1 -Think in reverse instead of finding the minimum prefix + suffix find the maximum subarray +Think in reverse; instead of finding the minimum prefix + suffix, find the maximum subarray.
    Hint 2 -to find the maximum subarray a is standard and can be done greedily +Finding the maximum subarray is standard and can be done greedily.
    diff --git a/problems/missing-ranges/README.md b/problems/missing-ranges/README.md index 484395253..0b127da34 100644 --- a/problems/missing-ranges/README.md +++ b/problems/missing-ranges/README.md @@ -9,7 +9,7 @@                  [Next >](../maximum-gap "Maximum Gap") -## [163. Missing Ranges (Medium)](https://leetcode.com/problems/missing-ranges "缺失的区间") +## [163. Missing Ranges (Easy)](https://leetcode.com/problems/missing-ranges "缺失的区间")

    Given a sorted integer array nums, where the range of elements are in the inclusive range [lower, upper], return its missing ranges.

    diff --git a/problems/nested-list-weight-sum/README.md b/problems/nested-list-weight-sum/README.md index 18040d25a..a7de0b83f 100644 --- a/problems/nested-list-weight-sum/README.md +++ b/problems/nested-list-weight-sum/README.md @@ -33,6 +33,7 @@ ### Related Topics [[Depth-first Search](../../tag/depth-first-search/README.md)] + [[Breadth-first Search](../../tag/breadth-first-search/README.md)] ### Similar Questions 1. [Nested List Weight Sum II](../nested-list-weight-sum-ii) (Medium) diff --git a/problems/network-delay-time/README.md b/problems/network-delay-time/README.md index a5703b8f6..f99307e18 100644 --- a/problems/network-delay-time/README.md +++ b/problems/network-delay-time/README.md @@ -11,33 +11,44 @@ ## [743. Network Delay Time (Medium)](https://leetcode.com/problems/network-delay-time "网络延迟时间") -

    There are N network nodes, labelled 1 to N.

    +

    You are given a network of n nodes, labeled from 1 to n. You are also given times, a list of travel times as directed edges times[i] = (ui, vi, wi), where ui is the source node, vi is the target node, and wi is the time it takes for a signal to travel from source to target.

    -

    Given times, a list of travel times as directed edges times[i] = (u, v, w), where u is the source node, v is the target node, and w is the time it takes for a signal to travel from source to target.

    - -

    Now, we send a signal from a certain node K. How long will it take for all nodes to receive the signal? If it is impossible, return -1.

    +

    We will send a signal from a given node k. Return the time it takes for all the n nodes to receive the signal. If it is impossible for all the n nodes to receive the signal, return -1.

     

    -

    Example 1:

    + +
    +Input: times = [[2,1,1],[2,3,1],[3,4,1]], n = 4, k = 2
    +Output: 2
    +
    -

    +

    Example 2:

    -Input: times = [[2,1,1],[2,3,1],[3,4,1]], N = 4, K = 2
    -Output: 2
    +Input: times = [[1,2,1]], n = 2, k = 1
    +Output: 1
     
    -

     

    +

    Example 3:

    -

    Note:

    +
    +Input: times = [[1,2,1]], n = 2, k = 2
    +Output: -1
    +
    -
      -
    1. N will be in the range [1, 100].
    2. -
    3. K will be in the range [1, N].
    4. -
    5. The length of times will be in the range [1, 6000].
    6. -
    7. All edges times[i] = (u, v, w) will have 1 <= u, v <= N and 0 <= w <= 100.
    8. -
    +

     

    +

    Constraints:

    + +
      +
    • 1 <= k <= n <= 100
    • +
    • 1 <= times.length <= 6000
    • +
    • times[i].length == 3
    • +
    • 1 <= ui, vi <= n
    • +
    • ui != vi
    • +
    • 0 <= wi <= 100
    • +
    • All the pairs (ui, vi) are unique. (i.e., no multiple edges.)
    • +
    ### Related Topics [[Heap](../../tag/heap/README.md)] diff --git a/problems/next-greater-element-i/README.md b/problems/next-greater-element-i/README.md index eacbe1de6..261f7079b 100644 --- a/problems/next-greater-element-i/README.md +++ b/problems/next-greater-element-i/README.md @@ -11,42 +11,44 @@ ## [496. Next Greater Element I (Easy)](https://leetcode.com/problems/next-greater-element-i "下一个更大元素 I") -

    -You are given two arrays (without duplicates) nums1 and nums2 where nums1’s elements are subset of nums2. Find all the next greater numbers for nums1's elements in the corresponding places of nums2. -

    +

    You are given two integer arrays nums1 and nums2 both of unique elements, where nums1 is a subset of nums2.

    -

    -The Next Greater Number of a number x in nums1 is the first greater number to its right in nums2. If it does not exist, output -1 for this number. -

    +

    Find all the next greater numbers for nums1's elements in the corresponding places of nums2.

    + +

    The Next Greater Number of a number x in nums1 is the first greater number to its right in nums2. If it does not exist, return -1 for this number.

    + +

     

    +

    Example 1:

    -

    Example 1:

    -Input: nums1 = [4,1,2], nums2 = [1,3,4,2].
    -Output: [-1,3,-1]
    -Explanation:
    -    For number 4 in the first array, you cannot find the next greater number for it in the second array, so output -1.
    -    For number 1 in the first array, the next greater number for it in the second array is 3.
    -    For number 2 in the first array, there is no next greater number for it in the second array, so output -1.
    -
    -

    - -

    Example 2:
    +Input: nums1 = [4,1,2], nums2 = [1,3,4,2] +Output: [-1,3,-1] +Explanation: +For number 4 in the first array, you cannot find the next greater number for it in the second array, so output -1. +For number 1 in the first array, the next greater number for it in the second array is 3. +For number 2 in the first array, there is no next greater number for it in the second array, so output -1.

    + +

    Example 2:

    +
    -Input: nums1 = [2,4], nums2 = [1,2,3,4].
    -Output: [3,-1]
    -Explanation:
    -    For number 2 in the first array, the next greater number for it in the second array is 3.
    -    For number 4 in the first array, there is no next greater number for it in the second array, so output -1.
    -
    -

    - - -

    Note:
    -

      -
    1. All elements in nums1 and nums2 are unique.
    2. -
    3. The length of both nums1 and nums2 would not exceed 1000.
    4. -
    -

    +Input: nums1 = [2,4], nums2 = [1,2,3,4] +Output: [3,-1] +Explanation: +For number 2 in the first array, the next greater number for it in the second array is 3. +For number 4 in the first array, there is no next greater number for it in the second array, so output -1. + +

     

    +

    Constraints:

    + +
      +
    • 1 <= nums1.length <= nums2.length <= 1000
    • +
    • 0 <= nums1[i], nums2[i] <= 104
    • +
    • All integers in nums1 and nums2 are unique.
    • +
    • All the integers of nums1 also appear in nums2.
    • +
    + +

     

    +Follow up: Could you find an O(nums1.length + nums2.length) solution? ### Related Topics [[Stack](../../tag/stack/README.md)] diff --git a/problems/non-decreasing-array/README.md b/problems/non-decreasing-array/README.md index bf06ba4f0..2978ce872 100644 --- a/problems/non-decreasing-array/README.md +++ b/problems/non-decreasing-array/README.md @@ -11,9 +11,9 @@ ## [665. Non-decreasing Array (Easy)](https://leetcode.com/problems/non-decreasing-array "非递减数列") -

    Given an array nums with n integers, your task is to check if it could become non-decreasing by modifying at most 1 element.

    +

    Given an array nums with n integers, your task is to check if it could become non-decreasing by modifying at most one element.

    -

    We define an array is non-decreasing if nums[i] <= nums[i + 1] holds for every i (0-based) such that (0 <= i <= n - 2).

    +

    We define an array is non-decreasing if nums[i] <= nums[i + 1] holds for every i (0-based) such that (0 <= i <= n - 2).

     

    Example 1:

    @@ -36,8 +36,9 @@

    Constraints:

      -
    • 1 <= n <= 10 ^ 4
    • -
    • - 10 ^ 5 <= nums[i] <= 10 ^ 5
    • +
    • n == nums.length
    • +
    • 1 <= n <= 104
    • +
    • -105 <= nums[i] <= 105
    ### Related Topics diff --git a/problems/non-negative-integers-without-consecutive-ones/README.md b/problems/non-negative-integers-without-consecutive-ones/README.md index a8a48a286..f5710de52 100644 --- a/problems/non-negative-integers-without-consecutive-ones/README.md +++ b/problems/non-negative-integers-without-consecutive-ones/README.md @@ -37,6 +37,6 @@ Among them, only integer 3 disobeys the rule (two consecutive ones) and the othe [[Dynamic Programming](../../tag/dynamic-programming/README.md)] ### Similar Questions - 1. [House Robber](../house-robber) (Easy) + 1. [House Robber](../house-robber) (Medium) 1. [House Robber II](../house-robber-ii) (Medium) 1. [Ones and Zeroes](../ones-and-zeroes) (Medium) diff --git a/problems/number-of-rectangles-that-can-form-the-largest-square/README.md b/problems/number-of-rectangles-that-can-form-the-largest-square/README.md new file mode 100644 index 000000000..282ba3127 --- /dev/null +++ b/problems/number-of-rectangles-that-can-form-the-largest-square/README.md @@ -0,0 +1,66 @@ + + + + + + + +[< Previous](../checking-existence-of-edge-length-limited-paths-ii "Checking Existence of Edge Length Limited Paths II") +                 +[Next >](../tuple-with-same-product "Tuple with Same Product") + +## [1725. Number Of Rectangles That Can Form The Largest Square (Easy)](https://leetcode.com/problems/number-of-rectangles-that-can-form-the-largest-square "可以形成最大正方形的矩形数目") + +

    You are given an array rectangles where rectangles[i] = [li, wi] represents the ith rectangle of length li and width wi.

    + +

    You can cut the ith rectangle to form a square with a side length of k if both k <= li and k <= wi. For example, if you have a rectangle [4,6], you can cut it to get a square with a side length of at most 4.

    + +

    Let maxLen be the side length of the largest square you can obtain from any of the given rectangles.

    + +

    Return the number of rectangles that can make a square with a side length of maxLen.

    + +

     

    +

    Example 1:

    + +
    +Input: rectangles = [[5,8],[3,9],[5,12],[16,5]]
    +Output: 3
    +Explanation: The largest squares you can get from each rectangle are of lengths [5,3,5,5].
    +The largest possible square is of length 5, and you can get it out of 3 rectangles.
    +
    + +

    Example 2:

    + +
    +Input: rectangles = [[2,3],[3,7],[4,3],[3,7]]
    +Output: 3
    +
    + +

     

    +

    Constraints:

    + +
      +
    • 1 <= rectangles.length <= 1000
    • +
    • rectangles[i].length == 2
    • +
    • 1 <= li, wi <= 109
    • +
    • li != wi
    • +
    + +### Related Topics + [[Greedy](../../tag/greedy/README.md)] + +### Hints +
    +Hint 1 +What is the length of the largest square the can be cut out of some rectangle? It'll be equal to min(rectangle.length, rectangle.width). Replace each rectangle with this value. +
    + +
    +Hint 2 +Calculate maxSize by iterating over the given rectangles and maximizing the answer with their values denoted in the first hint. +
    + +
    +Hint 3 +Then iterate again on the rectangles and calculate the number whose values = maxSize. +
    diff --git a/problems/paint-fence/README.md b/problems/paint-fence/README.md index 0b17bbdb1..739c6dee1 100644 --- a/problems/paint-fence/README.md +++ b/problems/paint-fence/README.md @@ -41,7 +41,7 @@ n and k are non-negative integers.

    [[Dynamic Programming](../../tag/dynamic-programming/README.md)] ### Similar Questions - 1. [House Robber](../house-robber) (Easy) + 1. [House Robber](../house-robber) (Medium) 1. [House Robber II](../house-robber-ii) (Medium) 1. [Paint House](../paint-house) (Medium) 1. [Paint House II](../paint-house-ii) (Hard) diff --git a/problems/paint-house/README.md b/problems/paint-house/README.md index a7582b0d1..4ec08d22b 100644 --- a/problems/paint-house/README.md +++ b/problems/paint-house/README.md @@ -31,7 +31,7 @@ All costs are positive integers.

    [[Dynamic Programming](../../tag/dynamic-programming/README.md)] ### Similar Questions - 1. [House Robber](../house-robber) (Easy) + 1. [House Robber](../house-robber) (Medium) 1. [House Robber II](../house-robber-ii) (Medium) 1. [Paint House II](../paint-house-ii) (Hard) 1. [Paint Fence](../paint-fence) (Easy) diff --git a/problems/palindrome-number/README.md b/problems/palindrome-number/README.md index 95d7cba96..442e51538 100644 --- a/problems/palindrome-number/README.md +++ b/problems/palindrome-number/README.md @@ -11,9 +11,9 @@ ## [9. Palindrome Number (Easy)](https://leetcode.com/problems/palindrome-number "回文数") -

    Determine whether an integer is a palindrome. An integer is a palindrome when it reads the same backward as forward.

    +

    Given an integer x, return true if x is palindrome integer.

    -

    Follow up: Could you solve it without converting the integer to a string?

    +

    An integer is a palindrome when it reads the same backward as forward. For example, 121 is palindrome while 123 is not.

     

    Example 1:

    @@ -53,6 +53,9 @@
  • -231 <= x <= 231 - 1
  • +

     

    +Follow up: Could you solve it without converting the integer to a string? + ### Related Topics [[Math](../../tag/math/README.md)] diff --git a/problems/pancake-sorting/README.md b/problems/pancake-sorting/README.md index e7c8561fa..da75550b4 100644 --- a/problems/pancake-sorting/README.md +++ b/problems/pancake-sorting/README.md @@ -11,18 +11,18 @@ ## [969. Pancake Sorting (Medium)](https://leetcode.com/problems/pancake-sorting "煎饼排序") -

    Given an array of integers arr, sort the array by performing a series of pancake flips.

    +

    Given an array of integers arr, sort the array by performing a series of pancake flips.

    In one pancake flip we do the following steps:

    • Choose an integer k where 1 <= k <= arr.length.
    • -
    • Reverse the sub-array arr[1...k].
    • +
    • Reverse the sub-array arr[0...k-1] (0-indexed).
    -

    For example, if arr = [3,2,1,4] and we performed a pancake flip choosing k = 3, we reverse the sub-array [3,2,1], so arr = [1,2,3,4] after the pancake flip at k = 3.

    +

    For example, if arr = [3,2,1,4] and we performed a pancake flip choosing k = 3, we reverse the sub-array [3,2,1], so arr = [1,2,3,4] after the pancake flip at k = 3.

    -

    Return the k-values corresponding to a sequence of pancake flips that sort arr. Any valid answer that sorts the array within 10 * arr.length flips will be judged as correct.

    +

    Return an array of the k-values corresponding to a sequence of pancake flips that sort arr. Any valid answer that sorts the array within 10 * arr.length flips will be judged as correct.

     

    Example 1:

    @@ -33,11 +33,10 @@ Explanation: We perform 4 pancake flips, with k values 4, 2, 4, and 3. Starting state: arr = [3, 2, 4, 1] -After 1st flip (k = 4): arr = [1, 4, 2, 3] -After 2nd flip (k = 2): arr = [4, 1, 2, 3] -After 3rd flip (k = 4): arr = [3, 2, 1, 4] -After 4th flip (k = 3): arr = [1, 2, 3, 4], which is sorted. -Notice that we return an array of the chosen k values of the pancake flips. +After 1st flip (k = 4): arr = [1, 4, 2, 3] +After 2nd flip (k = 2): arr = [4, 1, 2, 3] +After 3rd flip (k = 4): arr = [3, 2, 1, 4] +After 4th flip (k = 3): arr = [1, 2, 3, 4], which is sorted.

    Example 2:

    diff --git a/problems/path-sum-ii/README.md b/problems/path-sum-ii/README.md index 699a12656..bcb94c932 100644 --- a/problems/path-sum-ii/README.md +++ b/problems/path-sum-ii/README.md @@ -11,33 +11,41 @@ ## [113. Path Sum II (Medium)](https://leetcode.com/problems/path-sum-ii "路径总和 II") -

    Given a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the given sum.

    +

    Given the root of a binary tree and an integer targetSum, return all root-to-leaf paths where each path's sum equals targetSum.

    -

    Note: A leaf is a node with no children.

    +

    A leaf is a node with no children.

    -

    Example:

    - -

    Given the below binary tree and sum = 22,

    +

     

    +

    Example 1:

    + +
    +Input: root = [5,4,8,11,null,13,4,7,2,null,null,5,1], targetSum = 22
    +Output: [[5,4,11,2],[5,8,4,5]]
    +
    +

    Example 2:

    +
    -      5
    -     / \
    -    4   8
    -   /   / \
    -  11  13  4
    - /  \    / \
    -7    2  5   1
    +Input: root = [1,2,3], targetSum = 5
    +Output: []
     
    -

    Return:

    +

    Example 3:

    -[
    -   [5,4,11,2],
    -   [5,8,4,5]
    -]
    +Input: root = [1,2], targetSum = 0
    +Output: []
     
    +

     

    +

    Constraints:

    + +
      +
    • The number of nodes in the tree is in the range [0, 5000].
    • +
    • -1000 <= Node.val <= 1000
    • +
    • -1000 <= targetSum <= 1000
    • +
    + ### Related Topics [[Tree](../../tag/tree/README.md)] [[Depth-first Search](../../tag/depth-first-search/README.md)] diff --git a/problems/path-sum/README.md b/problems/path-sum/README.md index f0cf5b237..231679a08 100644 --- a/problems/path-sum/README.md +++ b/problems/path-sum/README.md @@ -11,25 +11,40 @@ ## [112. Path Sum (Easy)](https://leetcode.com/problems/path-sum "路径总和") -

    Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given sum.

    +

    Given the root of a binary tree and an integer targetSum, return true if the tree has a root-to-leaf path such that adding up all the values along the path equals targetSum.

    -

    Note: A leaf is a node with no children.

    +

    A leaf is a node with no children.

    -

    Example:

    +

     

    +

    Example 1:

    + +
    +Input: root = [5,4,8,11,null,13,4,7,2,null,null,null,1], targetSum = 22
    +Output: true
    +
    + +

    Example 2:

    + +
    +Input: root = [1,2,3], targetSum = 5
    +Output: false
    +
    -

    Given the below binary tree and sum = 22,

    +

    Example 3:

    -      5
    -     / \
    -    4   8
    -   /   / \
    -  11  13  4
    - /  \      \
    -7    2      1
    +Input: root = [1,2], targetSum = 0
    +Output: false
     
    -

    return true, as there exist a root-to-leaf path 5->4->11->2 which sum is 22.

    +

     

    +

    Constraints:

    + +
      +
    • The number of nodes in the tree is in the range [0, 5000].
    • +
    • -1000 <= Node.val <= 1000
    • +
    • -1000 <= targetSum <= 1000
    • +
    ### Related Topics [[Tree](../../tag/tree/README.md)] diff --git a/problems/peak-index-in-a-mountain-array/README.md b/problems/peak-index-in-a-mountain-array/README.md index 9435eeae1..019cb1b84 100644 --- a/problems/peak-index-in-a-mountain-array/README.md +++ b/problems/peak-index-in-a-mountain-array/README.md @@ -23,7 +23,7 @@ -

    Given an integer array arr that is guaranteed to be a mountain, return any i such that arr[0] < arr[1] < ... arr[i - 1] < arr[i] > arr[i + 1] > ... > arr[arr.length - 1].

    +

    Given an integer array arr that is guaranteed to be a mountain, return any i such that arr[0] < arr[1] < ... arr[i - 1] < arr[i] > arr[i + 1] > ... > arr[arr.length - 1].

     

    Example 1:

    @@ -51,6 +51,9 @@
  • arr is guaranteed to be a mountain array.
  • +

     

    +Follow up: Finding the O(n) is straightforward, could you find an O(log(n)) solution? + ### Related Topics [[Binary Search](../../tag/binary-search/README.md)] diff --git a/problems/perfect-squares/README.md b/problems/perfect-squares/README.md index 71e721af9..2a32572c3 100644 --- a/problems/perfect-squares/README.md +++ b/problems/perfect-squares/README.md @@ -11,21 +11,33 @@ ## [279. Perfect Squares (Medium)](https://leetcode.com/problems/perfect-squares "完全平方数") -

    Given a positive integer n, find the least number of perfect square numbers (for example, 1, 4, 9, 16, ...) which sum to n.

    +

    Given an integer n, return the least number of perfect square numbers that sum to n.

    -

    Example 1:

    +

    A perfect square is an integer that is the square of an integer; in other words, it is the product of some integer with itself. For example, 1, 4, 9, and 16 are perfect squares while 3 and 11 are not.

    + +

     

    +

    Example 1:

    -Input: n = 12
    -Output: 3 
    -Explanation: 12 = 4 + 4 + 4.
    +Input: n = 12 +Output: 3 +Explanation: 12 = 4 + 4 + 4. + -

    Example 2:

    +

    Example 2:

    -Input: n = 13
    -Output: 2
    -Explanation: 13 = 4 + 9.
    +Input: n = 13 +Output: 2 +Explanation: 13 = 4 + 9. + + +

     

    +

    Constraints:

    + +
      +
    • 1 <= n <= 104
    • +
    ### Related Topics [[Breadth-first Search](../../tag/breadth-first-search/README.md)] diff --git a/problems/products-worth-over-invoices/README.md b/problems/products-worth-over-invoices/README.md index 2b8857123..175170405 100644 --- a/problems/products-worth-over-invoices/README.md +++ b/problems/products-worth-over-invoices/README.md @@ -9,6 +9,6 @@                  [Next >](../goal-parser-interpretation "Goal Parser Interpretation") -## [1677. Product's Worth Over Invoices (Easy)](https://leetcode.com/problems/products-worth-over-invoices "") +## [1677. Product's Worth Over Invoices (Easy)](https://leetcode.com/problems/products-worth-over-invoices "发票中的产品金额") diff --git a/problems/projection-area-of-3d-shapes/README.md b/problems/projection-area-of-3d-shapes/README.md index 4b9df535e..0bd685f7e 100644 --- a/problems/projection-area-of-3d-shapes/README.md +++ b/problems/projection-area-of-3d-shapes/README.md @@ -11,124 +11,62 @@ ## [883. Projection Area of 3D Shapes (Easy)](https://leetcode.com/problems/projection-area-of-3d-shapes "三维形体投影面积") -

    On a N * N grid, we place some 1 * 1 * 1 cubes that are axis-aligned with the x, y, and z axes.

    +

    You are given an n x n grid where we place some 1 x 1 x 1 cubes that are axis-aligned with the x, y, and z axes.

    -

    Each value v = grid[i][j] represents a tower of v cubes placed on top of grid cell (i, j).

    +

    Each value v = grid[i][j] represents a tower of v cubes placed on top of the cell (i, j).

    -

    Now we view the projection of these cubes onto the xy, yz, and zx planes.

    +

    We view the projection of these cubes onto the xy, yz, and zx planes.

    -

    A projection is like a shadow, that maps our 3 dimensional figure to a 2 dimensional plane. 

    +

    A projection is like a shadow, that maps our 3-dimensional figure to a 2-dimensional plane. We are viewing the "shadow" when looking at the cubes from the top, the front, and the side.

    -

    Here, we are viewing the "shadow" when looking at the cubes from the top, the front, and the side.

    - -

    Return the total area of all three projections.

    +

    Return the total area of all three projections.

     

    - -
    -
      -
    -
    - -
    -
    -
      -
    -
    -
    - -
    -
    -
    -
    -
      -
    -
    -
    -
    -
    - -
    -
    -
    -
    -
    -
    -
    -
    -
      -
    -
    -
    -
    -
    -
    -
    -
    -
    - -

    Example 1:

    - +
    -Input: [[2]]
    -Output: 5
    +Input: grid = [[1,2],[3,4]]
    +Output: 17
    +Explanation: Here are the three projections ("shadows") of the shape made with each axis-aligned plane.
     
    -

    Example 2:

    -Input: [[1,2],[3,4]]
    -Output: 17
    -Explanation: 
    -Here are the three projections ("shadows") of the shape made with each axis-aligned plane.
    -
    +Input: grid = [[2]]
    +Output: 5
     
    -

    Example 3:

    -Input: [[1,0],[0,2]]
    -Output: 8
    +Input: grid = [[1,0],[0,2]]
    +Output: 8
     
    -

    Example 4:

    -Input: [[1,1,1],[1,0,1],[1,1,1]]
    -Output: 14
    +Input: grid = [[1,1,1],[1,0,1],[1,1,1]]
    +Output: 14
     
    -

    Example 5:

    -Input: [[2,2,2],[2,1,2],[2,2,2]]
    -Output: 21
    +Input: grid = [[2,2,2],[2,1,2],[2,2,2]]
    +Output: 21
     

     

    - -
    -
    -
    -

    Note:

    +

    Constraints:

      -
    • 1 <= grid.length = grid[0].length <= 50
    • +
    • n == grid.length
    • +
    • n == grid[i].length
    • +
    • 1 <= n <= 50
    • 0 <= grid[i][j] <= 50
    -
    -
    -
    -
    -
    -
    -
    -
    ### Related Topics [[Math](../../tag/math/README.md)] diff --git a/problems/range-module/README.md b/problems/range-module/README.md index 53f405c50..ceec5b9fd 100644 --- a/problems/range-module/README.md +++ b/problems/range-module/README.md @@ -45,7 +45,7 @@ ### Similar Questions 1. [Merge Intervals](../merge-intervals) (Medium) - 1. [Insert Interval](../insert-interval) (Hard) + 1. [Insert Interval](../insert-interval) (Medium) 1. [Data Stream as Disjoint Intervals](../data-stream-as-disjoint-intervals) (Hard) ### Hints diff --git a/problems/range-sum-query-mutable/README.md b/problems/range-sum-query-mutable/README.md index 8771af7ba..2fa493df9 100644 --- a/problems/range-sum-query-mutable/README.md +++ b/problems/range-sum-query-mutable/README.md @@ -11,27 +11,43 @@ ## [307. Range Sum Query - Mutable (Medium)](https://leetcode.com/problems/range-sum-query-mutable "区域和检索 - 数组可修改") -

    Given an integer array nums, find the sum of the elements between indices i and j (ij), inclusive.

    +

    Given an array nums and two types of queries where you should update the value of an index in the array, and retrieve the sum of a range in the array.

    -

    The update(i, val) function modifies nums by updating the element at index i to val.

    +

    Implement the NumArray class:

    -

    Example:

    +
      +
    • NumArray(int[] nums) Initializes the object with the integer array nums.
    • +
    • void update(int index, int val) Updates the value of nums[index] to be val.
    • +
    • int sumRange(int left, int right) Returns the sum of the subarray nums[left, right] (i.e., nums[left] + nums[left + 1], ..., nums[right]).
    • +
    -
    -Given nums = [1, 3, 5]
    +

     

    +

    Example 1:

    -sumRange(0, 2) -> 9 -update(1, 2) -sumRange(0, 2) -> 8 +
    +Input
    +["NumArray", "sumRange", "update", "sumRange"]
    +[[[1, 3, 5]], [0, 2], [1, 2], [0, 2]]
    +Output
    +[null, 9, null, 8]
    +
    +Explanation
    +NumArray numArray = new NumArray([1, 3, 5]);
    +numArray.sumRange(0, 2); // return 9 = sum([1,3,5])
    +numArray.update(1, 2);   // nums = [1,2,5]
    +numArray.sumRange(0, 2); // return 8 = sum([1,2,5])
     

     

    Constraints:

      -
    • The array is only modifiable by the update function.
    • -
    • You may assume the number of calls to update and sumRange function is distributed evenly.
    • -
    • 0 <= i <= j <= nums.length - 1
    • +
    • 1 <= nums.length <= 3 * 104
    • +
    • -100 <= nums[i] <= 100
    • +
    • 0 <= index < nums.length
    • +
    • -100 <= val <= 100
    • +
    • 0 <= left <= right < nums.length
    • +
    • At most 3 * 104 calls will be made to update and sumRange.
    ### Related Topics diff --git a/problems/reachable-nodes-in-subdivided-graph/README.md b/problems/reachable-nodes-in-subdivided-graph/README.md index b33cd0903..1fd1fb599 100644 --- a/problems/reachable-nodes-in-subdivided-graph/README.md +++ b/problems/reachable-nodes-in-subdivided-graph/README.md @@ -11,58 +11,53 @@ ## [882. Reachable Nodes In Subdivided Graph (Hard)](https://leetcode.com/problems/reachable-nodes-in-subdivided-graph "细分图中的可到达结点") -

    Starting with an undirected graph (the "original graph") with nodes from 0 to N-1, subdivisions are made to some of the edges.

    +

    You are given an undirected graph (the "original graph") with n nodes labeled from 0 to n - 1, subdivisions are made to some of the edges.

    -

    The graph is given as follows: edges[k] is a list of integer pairs (i, j, n) such that (i, j) is an edge of the original graph,

    +

    The graph is given as an array of edges where edges[i] = [ui, vi, cnti] indicates that there is an edge between nodes ui and vi in the original graph, and cnti is the total number of new nodes on that edge.

    -

    and n is the total number of new nodes on that edge. 

    +

    Then, the edge [ui, vi] is deleted from the original graph, and cnti new nodes (x1, x2, ..., xcnti) are added to the original graph, and cnti + 1 new edges (ui, x1), (x1, x2), (x2, x3), ..., (xcnti - 1 , xcnti), (xcnti, vi) are added to the original graph.

    -

    Then, the edge (i, j) is deleted from the original graph, n new nodes (x_1, x_2, ..., x_n) are added to the original graph,

    +

    Now, you start at node 0 from the original graph, and in each move, you travel along one edge.

    -

    and n+1 new edges (i, x_1), (x_1, x_2), (x_2, x_3), ..., (x_{n-1}, x_n), (x_n, j) are added to the original graph.

    - -

    Now, you start at node 0 from the original graph, and in each move, you travel along one edge. 

    - -

    Return how many nodes you can reach in at most M moves.

    +

    Return the number of nodes you can reach in at most maxMoves moves.

     

    -

    Example 1:

    - +
    -Input: edges = [[0,1,10],[0,2,1],[1,2,2]], M = 6, N = 3
    -Output: 13
    -Explanation: 
    -The nodes that are reachable in the final graph after M = 6 moves are indicated below.
    -
    +Input: edges = [[0,1,10],[0,2,1],[1,2,2]], maxMoves = 6, n = 3
    +Output: 13
    +Explanation: The nodes that are reachable in the final graph after maxMoves = 6 moves are indicated above.
     
    -

    Example 2:

    -Input: edges = [[0,1,4],[1,2,6],[0,2,8],[1,3,1]], M = 10, N = 4
    -Output: 23
    - -

     

    -
    +Input: edges = [[0,1,4],[1,2,6],[0,2,8],[1,3,1]], maxMoves = 10, n = 4 +Output: 23 +
    -

    Note:

    +

    Example 3:

    -
      -
    1. 0 <= edges.length <= 10000
    2. -
    3. 0 <= edges[i][0] < edges[i][1] < N
    4. -
    5. There does not exist any i != j for which edges[i][0] == edges[j][0] and edges[i][1] == edges[j][1].
    6. -
    7. The original graph has no parallel edges.
    8. -
    9. 0 <= edges[i][2] <= 10000
    10. -
    11. 0 <= M <= 10^9
    12. -
    13. 1 <= N <= 3000
    14. -
    15. A reachable node is a node that can be travelled to using at most M moves starting from node 0.
    16. -
    +
    +Input: edges = [[1,2,4],[1,4,5],[1,3,1],[2,3,4],[3,4,5]], maxMoves = 17, n = 5
    +Output: 1
    +Explanation: The graph is disconnected, you can only reach node 0
    +
    -
    -
     
    -
    +

     

    +

    Constraints:

    + +
      +
    • 0 <= edges.length <= min(n * (n - 1) / 2, 104)
    • +
    • edges[i].length == 3
    • +
    • 0 <= ui < vi < n
    • +
    • There are no multiple edges in the graph.
    • +
    • 0 <= cnti <= 104
    • +
    • 0 <= maxMoves <= 109
    • +
    • 1 <= n <= 3000
    • +
    ### Related Topics [[Heap](../../tag/heap/README.md)] + [[Breadth-first Search](../../tag/breadth-first-search/README.md)] diff --git a/problems/remove-nth-node-from-end-of-list/README.md b/problems/remove-nth-node-from-end-of-list/README.md index a18c4e920..451a0a8e4 100644 --- a/problems/remove-nth-node-from-end-of-list/README.md +++ b/problems/remove-nth-node-from-end-of-list/README.md @@ -9,7 +9,7 @@                  [Next >](../valid-parentheses "Valid Parentheses") -## [19. Remove Nth Node From End of List (Medium)](https://leetcode.com/problems/remove-nth-node-from-end-of-list "删除链表的倒数第N个节点") +## [19. Remove Nth Node From End of List (Medium)](https://leetcode.com/problems/remove-nth-node-from-end-of-list "删除链表的倒数第 N 个结点")

    Given the head of a linked list, remove the nth node from the end of the list and return its head.

    diff --git a/problems/reorder-data-in-log-files/README.md b/problems/reorder-data-in-log-files/README.md index 6bfee801b..769d19a18 100644 --- a/problems/reorder-data-in-log-files/README.md +++ b/problems/reorder-data-in-log-files/README.md @@ -11,34 +11,45 @@ ## [937. Reorder Data in Log Files (Easy)](https://leetcode.com/problems/reorder-data-in-log-files "重新排列日志文件") -

    You have an array of logs.  Each log is a space delimited string of words.

    +

    You have an array of logs. Each log is a space-delimited string of words.

    -

    For each log, the first word in each log is an alphanumeric identifier.  Then, either:

    +

    For each log, the first word in each log is an alphanumeric identifier. Then, either:

    • Each word after the identifier will consist only of lowercase letters, or;
    • Each word after the identifier will consist only of digits.
    -

    We will call these two varieties of logs letter-logs and digit-logs.  It is guaranteed that each log has at least one word after its identifier.

    +

    We will call these two varieties of logs letter-logs and digit-logs. It is guaranteed that each log has at least one word after its identifier.

    -

    Reorder the logs so that all of the letter-logs come before any digit-log.  The letter-logs are ordered lexicographically ignoring identifier, with the identifier used in case of ties.  The digit-logs should be put in their original order.

    +

    Reorder the logs so that all of the letter-logs come before any digit-log. The letter-logs are ordered lexicographically, ignoring identifiers, with the identifier used in case of ties. The digit-logs should be put in their original order.

    Return the final order of the logs.

     

    Example 1:

    -
    Input: logs = ["dig1 8 1 5 1","let1 art can","dig2 3 6","let2 own kit dig","let3 art zero"]
    -Output: ["let1 art can","let3 art zero","let2 own kit dig","dig1 8 1 5 1","dig2 3 6"]
    +
    +
    +Input: logs = ["dig1 8 1 5 1","let1 art can","dig2 3 6","let2 own kit dig","let3 art zero"]
    +Output: ["let1 art can","let3 art zero","let2 own kit dig","dig1 8 1 5 1","dig2 3 6"]
    +
    + +

    Example 2:

    + +
    +Input: logs = ["a1 9 2 3 1","g1 act car","zo4 4 7","ab1 off key dog","a8 act zoo"]
    +Output: ["g1 act car","a8 act zoo","ab1 off key dog","a1 9 2 3 1","zo4 4 7"]
     
    +

     

    Constraints:

    -
      -
    1. 0 <= logs.length <= 100
    2. +
        +
      • 1 <= logs.length <= 100
      • 3 <= logs[i].length <= 100
      • -
      • logs[i] is guaranteed to have an identifier, and a word after the identifier.
      • -
    +
  • All the tokens of logs[i] are separated by single spaces.
  • +
  • logs[i] is guaranteed to have an identifier and a word after the identifier.
  • + ### Related Topics [[String](../../tag/string/README.md)] diff --git a/problems/reverse-integer/README.md b/problems/reverse-integer/README.md index cd697a63e..443f96087 100644 --- a/problems/reverse-integer/README.md +++ b/problems/reverse-integer/README.md @@ -11,9 +11,9 @@ ## [7. Reverse Integer (Easy)](https://leetcode.com/problems/reverse-integer "整数反转") -

    Given a 32-bit signed integer, reverse digits of an integer.

    +

    Given a signed 32-bit integer x, return x with its digits reversed. If reversing x causes the value to go outside the signed 32-bit integer range [-231, 231 - 1], then return 0.

    -

    Note: Assume we are dealing with an environment that could only store integers within the 32-bit signed integer range: [−231,  231 − 1]. For this problem, assume that your function returns 0 when the reversed integer overflows.

    +

    Assume the environment does not allow you to store 64-bit integers (signed or unsigned).

     

    Example 1:

    diff --git a/problems/robot-bounded-in-circle/README.md b/problems/robot-bounded-in-circle/README.md index ead8a72f6..31aad4ab0 100644 --- a/problems/robot-bounded-in-circle/README.md +++ b/problems/robot-bounded-in-circle/README.md @@ -11,12 +11,12 @@ ## [1041. Robot Bounded In Circle (Medium)](https://leetcode.com/problems/robot-bounded-in-circle "困于环中的机器人") -

    On an infinite plane, a robot initially stands at (0, 0) and faces north.  The robot can receive one of three instructions:

    +

    On an infinite plane, a robot initially stands at (0, 0) and faces north. The robot can receive one of three instructions:

    • "G": go straight 1 unit;
    • "L": turn 90 degrees to the left;
    • -
    • "R": turn 90 degress to the right.
    • +
    • "R": turn 90 degrees to the right.

    The robot performs the instructions given in order, and repeats them forever.

    @@ -24,43 +24,35 @@

    Return true if and only if there exists a circle in the plane such that the robot never leaves the circle.

     

    -

    Example 1:

    -Input: "GGLLGG"
    -Output: true
    -Explanation: 
    -The robot moves from (0,0) to (0,2), turns 180 degrees, and then returns to (0,0).
    -When repeating these instructions, the robot remains in the circle of radius 2 centered at the origin.
    -
    +Input: instructions = "GGLLGG" +Output: true +Explanation: The robot moves from (0,0) to (0,2), turns 180 degrees, and then returns to (0,0). +When repeating these instructions, the robot remains in the circle of radius 2 centered at the origin.

    Example 2:

    -Input: "GG"
    -Output: false
    -Explanation: 
    -The robot moves north indefinitely.
    -
    +Input: instructions = "GG" +Output: false +Explanation: The robot moves north indefinitely.

    Example 3:

    -Input: "GL"
    -Output: true
    -Explanation: 
    -The robot moves from (0, 0) -> (0, 1) -> (-1, 1) -> (-1, 0) -> (0, 0) -> ...
    -
    +Input: instructions = "GL" +Output: true +Explanation: The robot moves from (0, 0) -> (0, 1) -> (-1, 1) -> (-1, 0) -> (0, 0) -> ...

     

    +

    Constraints:

    -

    Note:

    - -
      +
      • 1 <= instructions.length <= 100
      • -
      • instructions[i] is in {'G', 'L', 'R'}
      • -
    +
  • instructions[i] is 'G', 'L' or, 'R'.
  • + ### Related Topics [[Math](../../tag/math/README.md)] diff --git a/problems/search-in-a-binary-search-tree/README.md b/problems/search-in-a-binary-search-tree/README.md index 24a5e7f02..8baa90f04 100644 --- a/problems/search-in-a-binary-search-tree/README.md +++ b/problems/search-in-a-binary-search-tree/README.md @@ -11,32 +11,34 @@ ## [700. Search in a Binary Search Tree (Easy)](https://leetcode.com/problems/search-in-a-binary-search-tree "二叉搜索树中的搜索") -

    Given the root node of a binary search tree (BST) and a value. You need to find the node in the BST that the node's value equals the given value. Return the subtree rooted with that node. If such node doesn't exist, you should return NULL.

    +

    You are given the root of a binary search tree (BST) and an integer val.

    -

    For example, 

    +

    Find the node in the BST that the node's value equals val and return the subtree rooted with that node. If such a node does not exist, return null.

    +

     

    +

    Example 1:

    +
    -Given the tree:
    -        4
    -       / \
    -      2   7
    -     / \
    -    1   3
    -
    -And the value to search: 2
    +Input: root = [4,2,7,1,3], val = 2
    +Output: [2,1,3]
     
    -

    You should return this subtree:

    - +

    Example 2:

    +
    -      2     
    -     / \   
    -    1   3
    +Input: root = [4,2,7,1,3], val = 5
    +Output: []
     
    -

    In the example above, if we want to search the value 5, since there is no node with value 5, we should return NULL.

    +

     

    +

    Constraints:

    -

    Note that an empty tree is represented by NULL, therefore you would see the expected output (serialized tree format) as [], not null.

    +
      +
    • The number of nodes in the tree is in the range [1, 5000].
    • +
    • 1 <= Node.val <= 107
    • +
    • root is a binary search tree.
    • +
    • 1 <= val <= 107
    • +
    ### Related Topics [[Tree](../../tag/tree/README.md)] diff --git a/problems/set-mismatch/README.md b/problems/set-mismatch/README.md index 49bb9d549..9b96464a9 100644 --- a/problems/set-mismatch/README.md +++ b/problems/set-mismatch/README.md @@ -11,28 +11,27 @@ ## [645. Set Mismatch (Easy)](https://leetcode.com/problems/set-mismatch "错误的集合") -

    -The set S originally contains numbers from 1 to n. But unfortunately, due to the data error, one of the numbers in the set got duplicated to another number in the set, which results in repetition of one number and loss of another number. -

    +

    You have a set of integers s, which originally contains all the numbers from 1 to n. Unfortunately, due to some error, one of the numbers in s got duplicated to another number in the set, which results in repetition of one number and loss of another number.

    -

    -Given an array nums representing the data status of this set after the error. Your task is to firstly find the number occurs twice and then find the number that is missing. Return them in the form of an array. -

    +

    You are given an integer array nums representing the data status of this set after the error.

    +

    Find the number that occurs twice and the number that is missing and return them in the form of an array.

    -

    Example 1:
    -

    -Input: nums = [1,2,2,4]
    -Output: [2,3]
    +

     

    +

    Example 1:

    +
    Input: nums = [1,2,2,4]
    +Output: [2,3]
    +

    Example 2:

    +
    Input: nums = [1,1]
    +Output: [1,2]
     
    -

    - -

    Note:
    -

      -
    1. The given array size will in the range [2, 10000].
    2. -
    3. The given array's numbers won't have any order.
    4. -
    -

    +

     

    +

    Constraints:

    + +
      +
    • 2 <= nums.length <= 104
    • +
    • 1 <= nums[i] <= 104
    • +
    ### Related Topics [[Hash Table](../../tag/hash-table/README.md)] diff --git a/problems/shortest-path-to-get-food/README.md b/problems/shortest-path-to-get-food/README.md new file mode 100644 index 000000000..599559db3 --- /dev/null +++ b/problems/shortest-path-to-get-food/README.md @@ -0,0 +1,40 @@ + + + + + + + +[< Previous](../find-followers-count "Find Followers Count") +                 +[Next >](../the-number-of-employees-which-report-to-each-employee "The Number of Employees Which Report to Each Employee") + +## [1730. Shortest Path to Get Food (Medium)](https://leetcode.com/problems/shortest-path-to-get-food "") + + + +### Related Topics + [[Depth-first Search](../../tag/depth-first-search/README.md)] + [[Breadth-first Search](../../tag/breadth-first-search/README.md)] + [[Graph](../../tag/graph/README.md)] + +### Hints +
    +Hint 1 +Run BFS starting from the '*' position. +
    + +
    +Hint 2 +Keep the current number of the steps as a state in the queue. +
    + +
    +Hint 3 +The first time you reach a food, return the number of steps as the answer. +
    + +
    +Hint 4 +In case the queue is empty and you still did not manage to reach a food, return -1. +
    diff --git a/problems/shortest-unsorted-continuous-subarray/README.md b/problems/shortest-unsorted-continuous-subarray/README.md index b6debfd6d..3bf01a5d0 100644 --- a/problems/shortest-unsorted-continuous-subarray/README.md +++ b/problems/shortest-unsorted-continuous-subarray/README.md @@ -13,7 +13,7 @@

    Given an integer array nums, you need to find one continuous subarray that if you only sort this subarray in ascending order, then the whole array will be sorted in ascending order.

    -

    Return the shortest such subarray and output its length.

    +

    Return the shortest such subarray and output its length.

     

    Example 1:

    @@ -46,5 +46,8 @@
  • -105 <= nums[i] <= 105
  • +

     

    +Follow up: Can you solve it in O(n) time complexity? + ### Related Topics [[Array](../../tag/array/README.md)] diff --git a/problems/sort-colors/README.md b/problems/sort-colors/README.md index e5d4fdecb..c48d94b28 100644 --- a/problems/sort-colors/README.md +++ b/problems/sort-colors/README.md @@ -11,16 +11,9 @@ ## [75. Sort Colors (Medium)](https://leetcode.com/problems/sort-colors "颜色分类") -

    Given an array nums with n objects colored red, white, or blue, sort them in-place so that objects of the same color are adjacent, with the colors in the order red, white, and blue.

    +

    Given an array nums with n objects colored red, white, or blue, sort them in-place so that objects of the same color are adjacent, with the colors in the order red, white, and blue.

    -

    Here, we will use the integers 0, 1, and 2 to represent the color red, white, and blue respectively.

    - -

    Follow up:

    - -
      -
    • Could you solve this problem without using the library's sort function?
    • -
    • Could you come up with a one-pass algorithm using only O(1) constant space?
    • -
    +

    We will use the integers 0, 1, and 2 to represent the color red, white, and blue, respectively.

     

    Example 1:

    @@ -45,6 +38,14 @@
  • nums[i] is 0, 1, or 2.
  • +

     

    +

    Follow up:

    + +
      +
    • Could you solve this problem without using the library's sort function?
    • +
    • Could you come up with a one-pass algorithm using only O(1) constant space?
    • +
    + ### Related Topics [[Sort](../../tag/sort/README.md)] [[Array](../../tag/array/README.md)] diff --git a/problems/sort-the-matrix-diagonally/README.md b/problems/sort-the-matrix-diagonally/README.md index 31bb6d3b4..00118b71e 100644 --- a/problems/sort-the-matrix-diagonally/README.md +++ b/problems/sort-the-matrix-diagonally/README.md @@ -23,13 +23,20 @@ Output: [[1,1,1,1],[1,2,2,2],[1,2,3,3]]
    +

    Example 2:

    + +
    +Input: mat = [[11,25,66,1,69,7],[23,55,17,45,15,52],[75,31,36,44,58,8],[22,27,33,25,68,4],[84,28,14,11,5,50]]
    +Output: [[5,17,4,1,52,7],[11,11,25,45,8,69],[14,23,25,44,58,15],[22,27,31,36,50,66],[84,28,75,33,55,68]]
    +
    +

     

    Constraints:

      -
    • m == mat.length
    • -
    • n == mat[i].length
    • -
    • 1 <= m, n <= 100
    • +
    • m == mat.length
    • +
    • n == mat[i].length
    • +
    • 1 <= m, n <= 100
    • 1 <= mat[i][j] <= 100
    diff --git a/problems/string-to-integer-atoi/README.md b/problems/string-to-integer-atoi/README.md index 7324a1e60..4d1cda325 100644 --- a/problems/string-to-integer-atoi/README.md +++ b/problems/string-to-integer-atoi/README.md @@ -11,61 +11,105 @@ ## [8. String to Integer (atoi) (Medium)](https://leetcode.com/problems/string-to-integer-atoi "字符串转换整数 (atoi)") -

    Implement atoi which converts a string to an integer.

    +

    Implement the myAtoi(string s) function, which converts a string to a 32-bit signed integer (similar to C/C++'s atoi function).

    -

    The function first discards as many whitespace characters as necessary until the first non-whitespace character is found. Then, starting from this character takes an optional initial plus or minus sign followed by as many numerical digits as possible, and interprets them as a numerical value.

    +

    The algorithm for myAtoi(string s) is as follows:

    -

    The string can contain additional characters after those that form the integral number, which are ignored and have no effect on the behavior of this function.

    - -

    If the first sequence of non-whitespace characters in str is not a valid integral number, or if no such sequence exists because either str is empty or it contains only whitespace characters, no conversion is performed.

    - -

    If no valid conversion could be performed, a zero value is returned.

    +
      +
    1. Read in and ignore any leading whitespace.
    2. +
    3. Check if the next character (if not already at the end of the string) is '-' or '+'. Read this character in if it is either. This determines if the final result is negative or positive respectively. Assume the result is positive if neither is present.
    4. +
    5. Read in next the characters until the next non-digit charcter or the end of the input is reached. The rest of the string is ignored.
    6. +
    7. Convert these digits into an integer (i.e. "123" -> 123, "0032" -> 32). If no digits were read, then the integer is 0. Change the sign as necessary (from step 2).
    8. +
    9. If the integer is out of the 32-bit signed integer range [-231, 231 - 1], then clamp the integer so that it remains in the range. Specifically, integers less than -231 should be clamped to -231, and integers greater than 231 - 1 should be clamped to 231 - 1.
    10. +
    11. Return the integer as the final result.
    12. +

    Note:

    • Only the space character ' ' is considered a whitespace character.
    • -
    • Assume we are dealing with an environment that could only store integers within the 32-bit signed integer range: [−231,  231 − 1]. If the numerical value is out of the range of representable values, 231 − 1 or −231 is returned.
    • +
    • Do not ignore any characters other than the leading whitespace or the rest of the string after the digits.

     

    Example 1:

    -Input: str = "42"
    +Input: s = "42"
     Output: 42
    +Explanation: The underlined characters are what is read in, the caret is the current reader position.
    +Step 1: "42" (no characters read because there is no leading whitespace)
    +         ^
    +Step 2: "42" (no characters read because there is neither a '-' nor '+')
    +         ^
    +Step 3: "42" ("42" is read in)
    +           ^
    +The parsed integer is 42.
    +Since 42 is in the range [-231, 231 - 1], the final result is 42.
     

    Example 2:

    -Input: str = "   -42"
    +Input: s = "   -42"
     Output: -42
    -Explanation: The first non-whitespace character is '-', which is the minus sign. Then take as many numerical digits as possible, which gets 42.
    +Explanation:
    +Step 1: "   -42" (leading whitespace is read and ignored)
    +            ^
    +Step 2: "   -42" ('-' is read, so the result should be negative)
    +             ^
    +Step 3: "   -42" ("42" is read in)
    +               ^
    +The parsed integer is -42.
    +Since -42 is in the range [-231, 231 - 1], the final result is -42.
     

    Example 3:

    -Input: str = "4193 with words"
    +Input: s = "4193 with words"
     Output: 4193
    -Explanation: Conversion stops at digit '3' as the next character is not a numerical digit.
    +Explanation:
    +Step 1: "4193 with words" (no characters read because there is no leading whitespace)
    +         ^
    +Step 2: "4193 with words" (no characters read because there is neither a '-' nor '+')
    +         ^
    +Step 3: "4193 with words" ("4193" is read in; reading stops because the next character is a non-digit)
    +             ^
    +The parsed integer is 4193.
    +Since 4193 is in the range [-231, 231 - 1], the final result is 4193.
     

    Example 4:

    -Input: str = "words and 987"
    +Input: s = "words and 987"
     Output: 0
    -Explanation: The first non-whitespace character is 'w', which is not a numerical digit or a +/- sign. Therefore no valid conversion could be performed.
    +Explanation:
    +Step 1: "words and 987" (no characters read because there is no leading whitespace)
    +         ^
    +Step 2: "words and 987" (no characters read because there is neither a '-' nor '+')
    +         ^
    +Step 3: "words and 987" (reading stops immediately because there is a non-digit 'w')
    +         ^
    +The parsed integer is 0 because no digits were read.
    +Since 0 is in the range [-231, 231 - 1], the final result is 0.
     

    Example 5:

    -Input: str = "-91283472332"
    +Input: s = "-91283472332"
     Output: -2147483648
    -Explanation: The number "-91283472332" is out of the range of a 32-bit signed integer. Thefore INT_MIN (−231) is returned.
    +Explanation:
    +Step 1: "-91283472332" (no characters read because there is no leading whitespace)
    +         ^
    +Step 2: "-91283472332" ('-' is read, so the result should be negative)
    +          ^
    +Step 3: "-91283472332" ("91283472332" is read in)
    +                     ^
    +The parsed integer is -91283472332.
    +Since -91283472332 is less than the lower bound of the range [-231, 231 - 1], the final result is clamped to -231 = -2147483648. 
     

     

    @@ -73,7 +117,7 @@
    • 0 <= s.length <= 200
    • -
    • s consists of English letters (lower-case and upper-case), digits, ' ', '+', '-' and '.'.
    • +
    • s consists of English letters (lower-case and upper-case), digits (0-9), ' ', '+', '-', and '.'.
    ### Related Topics diff --git a/problems/subsets-ii/README.md b/problems/subsets-ii/README.md index 42c17dd50..212b49a70 100644 --- a/problems/subsets-ii/README.md +++ b/problems/subsets-ii/README.md @@ -11,24 +11,25 @@ ## [90. Subsets II (Medium)](https://leetcode.com/problems/subsets-ii "子集 II") -

    Given a collection of integers that might contain duplicates, nums, return all possible subsets (the power set).

    - -

    Note: The solution set must not contain duplicate subsets.

    - -

    Example:

    - -
    -Input: [1,2,2]
    -Output:
    -[
    -  [2],
    -  [1],
    -  [1,2,2],
    -  [2,2],
    -  [1,2],
    -  []
    -]
    +

    Given an integer array nums that may contain duplicates, return all possible subsets (the power set).

    + +

    The solution set must not contain duplicate subsets. Return the solution in any order.

    + +

     

    +

    Example 1:

    +
    Input: nums = [1,2,2]
    +Output: [[],[1],[1,2],[1,2,2],[2],[2,2]]
    +

    Example 2:

    +
    Input: nums = [0]
    +Output: [[],[0]]
     
    +

     

    +

    Constraints:

    + +
      +
    • 1 <= nums.length <= 10
    • +
    • -10 <= nums[i] <= 10
    • +
    ### Related Topics [[Array](../../tag/array/README.md)] diff --git a/problems/subsets/README.md b/problems/subsets/README.md index 075a60080..28e5bcd05 100644 --- a/problems/subsets/README.md +++ b/problems/subsets/README.md @@ -11,9 +11,9 @@ ## [78. Subsets (Medium)](https://leetcode.com/problems/subsets "子集") -

    Given an integer array nums, return all possible subsets (the power set).

    +

    Given an integer array nums of unique elements, return all possible subsets (the power set).

    -

    The solution set must not contain duplicate subsets.

    +

    The solution set must not contain duplicate subsets. Return the solution in any order.

     

    Example 1:

    diff --git a/problems/sum-of-subarray-minimums/README.md b/problems/sum-of-subarray-minimums/README.md index 349f90aa5..a34173d2a 100644 --- a/problems/sum-of-subarray-minimums/README.md +++ b/problems/sum-of-subarray-minimums/README.md @@ -11,32 +11,7 @@ ## [907. Sum of Subarray Minimums (Medium)](https://leetcode.com/problems/sum-of-subarray-minimums "子数组的最小值之和") -

    Given an array of integers A, find the sum of min(B), where B ranges over every (contiguous) subarray of A.

    - -

    Since the answer may be large, return the answer modulo 10^9 + 7.

    - -

     

    - -

    Example 1:

    - -
    -Input: [3,1,2,4]
    -Output: 17
    -Explanation: Subarrays are [3], [1], [2], [4], [3,1], [1,2], [2,4], [3,1,2], [1,2,4], [3,1,2,4]. 
    -Minimums are 3, 1, 2, 4, 1, 1, 2, 1, 1, 1.  Sum is 17.
    - -

     

    - -

    Note:

    - -
      -
    1. 1 <= A.length <= 30000
    2. -
    3. 1 <= A[i] <= 30000
    4. -
    - -
    -

     

    -
    +

    Given an array of integers arr, find the sum of min(b), where b ranges over every (contiguous) subarray of arr. Since the answer may be large, return the answer modulo 109 + 7.

     

    Example 1:

    diff --git a/problems/summary-ranges/README.md b/problems/summary-ranges/README.md index 4c7a94de8..f9d073e35 100644 --- a/problems/summary-ranges/README.md +++ b/problems/summary-ranges/README.md @@ -81,5 +81,5 @@ [[Array](../../tag/array/README.md)] ### Similar Questions - 1. [Missing Ranges](../missing-ranges) (Medium) + 1. [Missing Ranges](../missing-ranges) (Easy) 1. [Data Stream as Disjoint Intervals](../data-stream-as-disjoint-intervals) (Hard) diff --git a/problems/surface-area-of-3d-shapes/README.md b/problems/surface-area-of-3d-shapes/README.md index 03eb25c6d..f8544c12a 100644 --- a/problems/surface-area-of-3d-shapes/README.md +++ b/problems/surface-area-of-3d-shapes/README.md @@ -11,12 +11,14 @@ ## [892. Surface Area of 3D Shapes (Easy)](https://leetcode.com/problems/surface-area-of-3d-shapes "三维形体的表面积") -

    You are given an n x n grid where we can place some 1 x 1 x 1 cubes.

    +

    You are given an n x n grid where you have placed some 1 x 1 x 1 cubes. Each value v = grid[i][j] represents a tower of v cubes placed on top of cell (i, j).

    -

    Each value v = grid[i][j] represents a tower of v cubes placed on top of the grid cell (i, j).

    +

    After placing these cubes, you have decided to glue any directly adjacent cubes to each other, forming several irregular 3D shapes.

    Return the total surface area of the resulting shapes.

    +

    Note: The bottom face of each shape counts toward its surface area.

    +

     

    Example 1:

    diff --git a/problems/the-number-of-employees-which-report-to-each-employee/README.md b/problems/the-number-of-employees-which-report-to-each-employee/README.md new file mode 100644 index 000000000..593e0015c --- /dev/null +++ b/problems/the-number-of-employees-which-report-to-each-employee/README.md @@ -0,0 +1,14 @@ + + + + + + + +[< Previous](../shortest-path-to-get-food "Shortest Path to Get Food") +                 +[Next >](../find-the-highest-altitude "Find the Highest Altitude") + +## [1731. The Number of Employees Which Report to Each Employee (Easy)](https://leetcode.com/problems/the-number-of-employees-which-report-to-each-employee "") + + diff --git a/problems/the-number-of-employees-which-report-to-each-employee/mysql_schemas.sql b/problems/the-number-of-employees-which-report-to-each-employee/mysql_schemas.sql new file mode 100644 index 000000000..a819253b1 --- /dev/null +++ b/problems/the-number-of-employees-which-report-to-each-employee/mysql_schemas.sql @@ -0,0 +1,6 @@ +Create table If Not Exists Employees(employee_id int, name varchar(20), reports_to int, age int); +Truncate table Employees; +insert into Employees (employee_id, name, reports_to, age) values ('9', 'Hercy', 'None', '43'); +insert into Employees (employee_id, name, reports_to, age) values ('6', 'Alice', '9', '41'); +insert into Employees (employee_id, name, reports_to, age) values ('4', 'Bob', '9', '36'); +insert into Employees (employee_id, name, reports_to, age) values ('2', 'Winston', 'None', '37'); diff --git a/problems/third-maximum-number/README.md b/problems/third-maximum-number/README.md index 3fad785b5..8f5da7966 100644 --- a/problems/third-maximum-number/README.md +++ b/problems/third-maximum-number/README.md @@ -43,8 +43,8 @@ Both numbers with value 2 are both considered as second maximum.

    Constraints:

      -
    • 1 <= nums.length <= 104
    • -
    • 231 <= nums[i] <= 231 - 1
    • +
    • 1 <= nums.length <= 104
    • +
    • -231 <= nums[i] <= 231 - 1

     

    diff --git a/problems/three-equal-parts/README.md b/problems/three-equal-parts/README.md index 1996c733e..93e627f70 100644 --- a/problems/three-equal-parts/README.md +++ b/problems/three-equal-parts/README.md @@ -11,50 +11,39 @@ ## [927. Three Equal Parts (Hard)](https://leetcode.com/problems/three-equal-parts "三等分") -

    Given an array A of 0s and 1s, divide the array into 3 non-empty parts such that all of these parts represent the same binary value.

    +

    You are given an array arr which consists of only zeros and ones, divide the array into three non-empty parts such that all of these parts represent the same binary value.

    -

    If it is possible, return any [i, j] with i+1 < j, such that:

    +

    If it is possible, return any [i, j] with i + 1 < j, such that:

      -
    • A[0], A[1], ..., A[i] is the first part;
    • -
    • A[i+1], A[i+2], ..., A[j-1] is the second part, and
    • -
    • A[j], A[j+1], ..., A[A.length - 1] is the third part.
    • -
    • All three parts have equal binary value.
    • +
    • arr[0], arr[1], ..., arr[i] is the first part,
    • +
    • arr[i + 1], arr[i + 2], ..., arr[j - 1] is the second part, and
    • +
    • arr[j], arr[j + 1], ..., arr[arr.length - 1] is the third part.
    • +
    • All three parts have equal binary values.

    If it is not possible, return [-1, -1].

    -

    Note that the entire part is used when considering what binary value it represents.  For example, [1,1,0] represents 6 in decimal, not 3.  Also, leading zeros are allowed, so [0,1,1] and [1,1] represent the same value.

    +

    Note that the entire part is used when considering what binary value it represents. For example, [1,1,0] represents 6 in decimal, not 3. Also, leading zeros are allowed, so [0,1,1] and [1,1] represent the same value.

     

    -

    Example 1:

    - -
    -Input: [1,0,1,0,1]
    -Output: [0,3]
    +
    Input: arr = [1,0,1,0,1]
    +Output: [0,3]
    +

    Example 2:

    +
    Input: arr = [1,1,0,1,1]
    +Output: [-1,-1]
    +

    Example 3:

    +
    Input: arr = [1,1,0,0,1]
    +Output: [0,2]
     
    - -
    -

    Example 2:

    - -
    -Input: [1,1,0,1,1]
    -Output: [-1,-1]
    -
    -

     

    +

    Constraints:

    -

    Note:

    - -
      -
    1. 3 <= A.length <= 30000
    2. -
    3. A[i] == 0 or A[i] == 1
    4. -
    - -
    -
     
    -
    +
      +
    • 3 <= arr.length <= 3 * 104
    • +
    • arr[i] is 0 or 1
    • +
    ### Related Topics [[Greedy](../../tag/greedy/README.md)] diff --git a/problems/trapping-rain-water/README.md b/problems/trapping-rain-water/README.md index 04053ca4f..eebeecd03 100644 --- a/problems/trapping-rain-water/README.md +++ b/problems/trapping-rain-water/README.md @@ -42,6 +42,7 @@ [[Stack](../../tag/stack/README.md)] [[Array](../../tag/array/README.md)] [[Two Pointers](../../tag/two-pointers/README.md)] + [[Dynamic Programming](../../tag/dynamic-programming/README.md)] ### Similar Questions 1. [Container With Most Water](../container-with-most-water) (Medium) diff --git a/problems/trim-a-binary-search-tree/README.md b/problems/trim-a-binary-search-tree/README.md index b49488b06..cbeb41662 100644 --- a/problems/trim-a-binary-search-tree/README.md +++ b/problems/trim-a-binary-search-tree/README.md @@ -9,7 +9,7 @@                  [Next >](../maximum-swap "Maximum Swap") -## [669. Trim a Binary Search Tree (Easy)](https://leetcode.com/problems/trim-a-binary-search-tree "修剪二叉搜索树") +## [669. Trim a Binary Search Tree (Medium)](https://leetcode.com/problems/trim-a-binary-search-tree "修剪二叉搜索树")

    Given the root of a binary search tree and the lowest and highest boundaries as low and high, trim the tree so that all its elements lies in [low, high]. Trimming the tree should not change the relative structure of the elements that will remain in the tree (i.e., any node's descendant should remain a descendant). It can be proven that there is a unique answer.

    @@ -64,3 +64,4 @@ ### Related Topics [[Tree](../../tag/tree/README.md)] + [[Recursion](../../tag/recursion/README.md)] diff --git a/problems/trips-and-users/README.md b/problems/trips-and-users/README.md index fba9141a1..6b5209d40 100644 --- a/problems/trips-and-users/README.md +++ b/problems/trips-and-users/README.md @@ -11,55 +11,90 @@ ## [262. Trips and Users (Hard)](https://leetcode.com/problems/trips-and-users "行程和用户") -

    The Trips table holds all taxi trips. Each trip has a unique Id, while Client_Id and Driver_Id are both foreign keys to the Users_Id at the Users table. Status is an ENUM type of (‘completed’, ‘cancelled_by_driver’, ‘cancelled_by_client’).

    +

    Table: Trips

    -+----+-----------+-----------+---------+--------------------+----------+
    -| Id | Client_Id | Driver_Id | City_Id |        Status      |Request_at|
    -+----+-----------+-----------+---------+--------------------+----------+
    -| 1  |     1     |    10     |    1    |     completed      |2013-10-01|
    -| 2  |     2     |    11     |    1    | cancelled_by_driver|2013-10-01|
    -| 3  |     3     |    12     |    6    |     completed      |2013-10-01|
    -| 4  |     4     |    13     |    6    | cancelled_by_client|2013-10-01|
    -| 5  |     1     |    10     |    1    |     completed      |2013-10-02|
    -| 6  |     2     |    11     |    6    |     completed      |2013-10-02|
    -| 7  |     3     |    12     |    6    |     completed      |2013-10-02|
    -| 8  |     2     |    12     |    12   |     completed      |2013-10-03|
    -| 9  |     3     |    10     |    12   |     completed      |2013-10-03| 
    -| 10 |     4     |    13     |    12   | cancelled_by_driver|2013-10-03|
    -+----+-----------+-----------+---------+--------------------+----------+
    ++-------------+----------+
    +| Column Name | Type     |
    ++-------------+----------+
    +| Id          | int      |
    +| Client_Id   | int      |
    +| Driver_Id   | int      |
    +| City_Id     | int      |
    +| Status      | enum     |
    +| Request_at  | date     |     
    ++-------------+----------+
    +Id is the primary key for this table.
    +The table holds all taxi trips. Each trip has a unique Id, while Client_Id and Driver_Id are both foreign keys to the Users_Id at the Users table.
    +Status is an ENUM type of (‘completed’, ‘cancelled_by_driver’, ‘cancelled_by_client’).
     
    -

    The Users table holds all users. Each user has an unique Users_Id, and Role is an ENUM type of (‘client’, ‘driver’, ‘partner’).

    +

     

    + +

    Table: Users

    -+----------+--------+--------+
    -| Users_Id | Banned |  Role  |
    -+----------+--------+--------+
    -|    1     |   No   | client |
    -|    2     |   Yes  | client |
    -|    3     |   No   | client |
    -|    4     |   No   | client |
    -|    10    |   No   | driver |
    -|    11    |   No   | driver |
    -|    12    |   No   | driver |
    -|    13    |   No   | driver |
    -+----------+--------+--------+
    ++-------------+----------+
    +| Column Name | Type     |
    ++-------------+----------+
    +| Users_Id    | int      |
    +| Banned      | enum     |
    +| Role        | enum     |
    ++-------------+----------+
    +Users_Id is the primary key for this table.
    +The table holds all users. Each user has a unique Users_Id, and Role is an ENUM type of (‘client’, ‘driver’, ‘partner’).
    +Status is an ENUM type of (‘Yes’, ‘No’).
     
    -

    Write a SQL query to find the cancellation rate of requests made by unbanned users (both client and driver must be unbanned) between Oct 1, 2013 and Oct 3, 2013. The cancellation rate is computed by dividing the number of canceled (by client or driver) requests made by unbanned users by the total number of requests made by unbanned users.

    +

     

    + +

    Write a SQL query to find the cancellation rate of requests made by unbanned users (both client and driver must be unbanned) between "2013-10-01" and "2013-10-01".

    + +

    The cancellation rate is computed by dividing the number of canceled (by client or driver) requests made by unbanned users by the total number of requests made by unbanned users.

    + +

    Return the result table in any order. Round Cancellation Rate to two decimal points.

    -

    For the above tables, your SQL query should return the following rows with the cancellation rate being rounded to two decimal places.

    +

    The query result format is in the following example:

    + +

     

    +Trips table:
    ++----+-----------+-----------+---------+---------------------+------------+
    +| Id | Client_Id | Driver_Id | City_Id | Status              | Request_at |
    ++----+-----------+-----------+---------+---------------------+------------+
    +| 1  | 1         | 10        | 1       | completed           | 2013-10-01 |
    +| 2  | 2         | 11        | 1       | cancelled_by_driver | 2013-10-01 |
    +| 3  | 3         | 12        | 6       | completed           | 2013-10-01 |
    +| 4  | 4         | 13        | 6       | cancelled_by_client | 2013-10-01 |
    +| 5  | 1         | 10        | 1       | completed           | 2013-10-02 |
    +| 6  | 2         | 11        | 6       | completed           | 2013-10-02 |
    +| 7  | 3         | 12        | 6       | completed           | 2013-10-02 |
    +| 8  | 2         | 12        | 12      | completed           | 2013-10-03 |
    +| 9  | 3         | 10        | 12      | completed           | 2013-10-03 |
    +| 10 | 4         | 13        | 12      | cancelled_by_driver | 2013-10-03 |
    ++----+-----------+-----------+---------+---------------------+------------+
    +
    +Users table:
    ++----------+--------+--------+
    +| Users_Id | Banned | Role   |
    ++----------+--------+--------+
    +| 1        | No     | client |
    +| 2        | Yes    | client |
    +| 3        | No     | client |
    +| 4        | No     | client |
    +| 10       | No     | driver |
    +| 11       | No     | driver |
    +| 12       | No     | driver |
    +| 13       | No     | driver |
    ++----------+--------+--------+
    +
    +Result table:
     +------------+-------------------+
    -|     Day    | Cancellation Rate |
    +| Day        | Cancellation Rate |
     +------------+-------------------+
    -| 2013-10-01 |       0.33        |
    -| 2013-10-02 |       0.00        |
    -| 2013-10-03 |       0.50        |
    +| 2013-10-01 | 0.33              |
    +| 2013-10-02 | 0.00              |
    +| 2013-10-03 | 0.50              |
     +------------+-------------------+
     
    - -

    Credits:
    -Special thanks to @cak1erlizhou for contributing this question, writing the problem description and adding part of the test cases.

    diff --git a/problems/tuple-with-same-product/README.md b/problems/tuple-with-same-product/README.md new file mode 100644 index 000000000..fe5ce5a96 --- /dev/null +++ b/problems/tuple-with-same-product/README.md @@ -0,0 +1,75 @@ + + + + + + + +[< Previous](../number-of-rectangles-that-can-form-the-largest-square "Number Of Rectangles That Can Form The Largest Square") +                 +[Next >](../largest-submatrix-with-rearrangements "Largest Submatrix With Rearrangements") + +## [1726. Tuple with Same Product (Medium)](https://leetcode.com/problems/tuple-with-same-product "同积元组") + +

    Given an array nums of distinct positive integers, return the number of tuples (a, b, c, d) such that a * b = c * d where a, b, c, and d are elements of nums, and a != b != c != d.

    + +

     

    +

    Example 1:

    + +
    +Input: nums = [2,3,4,6]
    +Output: 8
    +Explanation: There are 8 valid tuples:
    +(2,6,3,4) , (2,6,4,3) , (6,2,3,4) , (6,2,4,3)
    +(3,4,2,6) , (4,3,2,6) , (3,4,6,2) , (4,3,6,2)
    +
    + +

    Example 2:

    + +
    +Input: nums = [1,2,4,5,10]
    +Output: 16
    +Explanation: There are 16 valids tuples:
    +(1,10,2,5) , (1,10,5,2) , (10,1,2,5) , (10,1,5,2)
    +(2,5,1,10) , (2,5,10,1) , (5,2,1,10) , (5,2,10,1)
    +(2,10,4,5) , (2,10,5,4) , (10,2,4,5) , (10,2,4,5)
    +(4,5,2,10) , (4,5,10,2) , (5,4,2,10) , (5,4,10,2)
    +
    + +

    Example 3:

    + +
    +Input: nums = [2,3,4,6,8,12]
    +Output: 40
    +
    + +

    Example 4:

    + +
    +Input: nums = [2,3,5,7]
    +Output: 0
    +
    + +

     

    +

    Constraints:

    + +
      +
    • 1 <= nums.length <= 1000
    • +
    • 1 <= nums[i] <= 104
    • +
    • All elements in nums are distinct.
    • +
    + +### Related Topics + [[Array](../../tag/array/README.md)] + [[Hash Table](../../tag/hash-table/README.md)] + +### Hints +
    +Hint 1 +Note that all of the integers are distinct. This means that each time a product is formed it must be formed by two unique integers. +
    + +
    +Hint 2 +Count the frequency of each product of 2 distinct numbers. Then calculate the permutations formed. +
    diff --git a/problems/two-sum-ii-input-array-is-sorted/README.md b/problems/two-sum-ii-input-array-is-sorted/README.md index 9b7ad3599..cbbdebf3f 100644 --- a/problems/two-sum-ii-input-array-is-sorted/README.md +++ b/problems/two-sum-ii-input-array-is-sorted/README.md @@ -11,16 +11,11 @@ ## [167. Two Sum II - Input array is sorted (Easy)](https://leetcode.com/problems/two-sum-ii-input-array-is-sorted "两数之和 II - 输入有序数组") -

    Given an array of integers that is already sorted in ascending order, find two numbers such that they add up to a specific target number.

    +

    Given an array of integers numbers that is already sorted in ascending order, find two numbers such that they add up to a specific target number.

    -

    The function twoSum should return indices of the two numbers such that they add up to the target, where index1 must be less than index2.

    +

    Return the indices of the two numbers (1-indexed) as an integer array answer of size 2, where 1 <= answer[0] < answer[1] <= numbers.length.

    -

    Note:

    - -
      -
    • Your returned answers (both index1 and index2) are not zero-based.
    • -
    • You may assume that each input would have exactly one solution and you may not use the same element twice.
    • -
    +

    You may assume that each input would have exactly one solution and you may not use the same element twice.

     

    Example 1:

    @@ -49,10 +44,11 @@

    Constraints:

      -
    • 2 <= nums.length <= 3 * 104
    • -
    • -1000 <= nums[i] <= 1000
    • -
    • nums is sorted in increasing order.
    • +
    • 2 <= numbers.length <= 3 * 104
    • +
    • -1000 <= numbers[i] <= 1000
    • +
    • numbers is sorted in increasing order.
    • -1000 <= target <= 1000
    • +
    • Only one valid answer exists.
    ### Related Topics diff --git a/problems/ugly-number-iii/README.md b/problems/ugly-number-iii/README.md index 5cd9b128f..03f1f90e1 100644 --- a/problems/ugly-number-iii/README.md +++ b/problems/ugly-number-iii/README.md @@ -11,9 +11,9 @@ ## [1201. Ugly Number III (Medium)](https://leetcode.com/problems/ugly-number-iii "丑数 III") -

    Write a program to find the n-th ugly number.

    +

    Given four integers n, a, b, and c, return the nth ugly number.

    -

    Ugly numbers are positive integers which are divisible by a or b or c.

    +

    Ugly numbers are positive integers that are divisible by a, b, or c.

     

    Example 1:

    @@ -50,9 +50,9 @@

    Constraints:

      -
    • 1 <= n, a, b, c <= 10^9
    • -
    • 1 <= a * b * c <= 10^18
    • -
    • It's guaranteed that the result will be in range [1, 2 * 10^9]
    • +
    • 1 <= n, a, b, c <= 109
    • +
    • 1 <= a * b * c <= 1018
    • +
    • It is guaranteed that the result will be in range [1, 2 * 109].
    ### Related Topics diff --git a/problems/unique-binary-search-trees-ii/README.md b/problems/unique-binary-search-trees-ii/README.md index 482638ce5..b4b0445f3 100644 --- a/problems/unique-binary-search-trees-ii/README.md +++ b/problems/unique-binary-search-trees-ii/README.md @@ -11,35 +11,28 @@ ## [95. Unique Binary Search Trees II (Medium)](https://leetcode.com/problems/unique-binary-search-trees-ii "不同的二叉搜索树 II") -

    Given an integer n, generate all structurally unique BST's (binary search trees) that store values 1 ... n.

    +

    Given an integer n, return all the structurally unique BST's (binary search trees), which has exactly n nodes of unique values from 1 to n. Return the answer in any order.

    -

    Example:

    +

     

    +

    Example 1:

    + +
    +Input: n = 3
    +Output: [[1,null,2,null,3],[1,null,3,2],[2,1,3],[3,1,null,null,2],[3,2,null,1]]
    +
    + +

    Example 2:

    -Input: 3
    -Output:
    -[
    -  [1,null,3,2],
    -  [3,2,null,1],
    -  [3,1,null,null,2],
    -  [2,1,3],
    -  [1,null,2,null,3]
    -]
    -Explanation:
    -The above output corresponds to the 5 unique BST's shown below:
    -
    -   1         3     3      2      1
    -    \       /     /      / \      \
    -     3     2     1      1   3      2
    -    /     /       \                 \
    -   2     1         2                 3
    +Input: n = 1
    +Output: [[1]]
     

     

    Constraints:

      -
    • 0 <= n <= 8
    • +
    • 1 <= n <= 8
    ### Related Topics diff --git a/problems/unique-binary-search-trees/README.md b/problems/unique-binary-search-trees/README.md index f95e1a39d..ab550f3e7 100644 --- a/problems/unique-binary-search-trees/README.md +++ b/problems/unique-binary-search-trees/README.md @@ -11,21 +11,21 @@ ## [96. Unique Binary Search Trees (Medium)](https://leetcode.com/problems/unique-binary-search-trees "不同的二叉搜索树") -

    Given n, how many structurally unique BST's (binary search trees) that store values 1 ... n?

    - -

    Example:

    +

    Given an integer n, return the number of structurally unique BST's (binary search trees) which has exactly n nodes of unique values from 1 to n.

    +

     

    +

    Example 1:

    +
    -Input: 3
    +Input: n = 3
     Output: 5
    -Explanation:
    -Given n = 3, there are a total of 5 unique BST's:
    -
    -   1         3     3      2      1
    -    \       /     /      / \      \
    -     3     2     1      1   3      2
    -    /     /       \                 \
    -   2     1         2                 3
    +
    + +

    Example 2:

    + +
    +Input: n = 1
    +Output: 1
     

     

    diff --git a/problems/valid-number/README.md b/problems/valid-number/README.md index 371b589a2..3425706a8 100644 --- a/problems/valid-number/README.md +++ b/problems/valid-number/README.md @@ -11,49 +11,72 @@ ## [65. Valid Number (Hard)](https://leetcode.com/problems/valid-number "有效数字") -

    Validate if a given string can be interpreted as a decimal number.

    - -

    Some examples:
    -"0" => true
    -" 0.1 " => true
    -"abc" => false
    -"1 a" => false
    -"2e10" => true
    -" -90e3   " => true
    -" 1e" => false
    -"e3" => false
    -" 6e-1" => true
    -" 99e2.5 " => false
    -"53.5e93" => true
    -" --6 " => false
    -"-+3" => false
    -"95a54e53" => false

    - -

    Note: It is intended for the problem statement to be ambiguous. It would be best if you gathered all requirements up front before implementing one. However, here is a list of characters that can be in a valid decimal number:

    +

    A valid number can be split up into these components (in order):

    -
      -
    • Numbers 0-9
    • -
    • Exponent - "e"
    • -
    • Positive/negative sign - "+"/"-"
    • -
    • Decimal point - "."
    • -
    +
      +
    1. A decimal number or an integer.
    2. +
    3. (Optional) An 'e' or 'E', followed by an integer.
    4. +
    + +

    A decimal number can be split up into these components (in order):

    + +
      +
    1. (Optional) A sign character (either '+' or '-').
    2. +
    3. One of the following formats: +
        +
      1. At least one digit, followed by a dot '.'.
      2. +
      3. At least one digit, followed by a dot '.', followed by at least one digit.
      4. +
      5. A dot '.', followed by at least one digit.
      6. +
      +
    4. +
    + +

    An integer can be split up into these components (in order):

    -

    Of course, the context of these characters also matters in the input.

    +
      +
    1. (Optional) A sign character (either '+' or '-').
    2. +
    3. At least one digit.
    4. +
    + +

    For example, all the following are valid numbers: ["2", "0089", "-0.1", "+3.14", "4.", "-.9", "2e10", "-90E3", "3e+7", "+6e-1", "53.5e93", "-123.456e789"], while the following are not valid numbers: ["abc", "1a", "1e", "e3", "99e2.5", "--6", "-+3", "95a54e53"].

    + +

    Given a string s, return true if s is a valid number.

     

    Example 1:

    -
    Input: s = "0"
    +
    +
    +Input: s = "0"
     Output: true
    -

    Example 2:

    -
    Input: s = "3"
    +
    + +

    Example 2:

    + +
    +Input: s = "e"
    +Output: false
    +
    + +

    Example 3:

    + +
    +Input: s = "."
    +Output: false
    +
    + +

    Example 4:

    + +
    +Input: s = ".1"
     Output: true
     
    +

     

    Constraints:

    • 1 <= s.length <= 20
    • -
    • s consists of only English letters, digits, space ' ', plus '+', minus '-', or dot '.'.
    • +
    • s consists of only English letters (both uppercase and lowercase), digits (0-9), plus '+', minus '-', or dot '.'.
    ### Related Topics diff --git a/problems/vertical-order-traversal-of-a-binary-tree/README.md b/problems/vertical-order-traversal-of-a-binary-tree/README.md index 0830cfee7..1906502cf 100644 --- a/problems/vertical-order-traversal-of-a-binary-tree/README.md +++ b/problems/vertical-order-traversal-of-a-binary-tree/README.md @@ -11,15 +11,13 @@ ## [987. Vertical Order Traversal of a Binary Tree (Medium)](https://leetcode.com/problems/vertical-order-traversal-of-a-binary-tree "二叉树的垂序遍历") -

    Given the root of a binary tree, return the vertical order traversal of its nodes values.

    +

    Given the root of a binary tree, calculate the vertical order traversal of the binary tree.

    -

    For each node at position (x, y), its left and right children respectively will be at positions (x - 1, y - 1) and (x + 1, y - 1).

    +

    For each node at position (x, y), its left and right children will be at positions (x - 1, y - 1) and (x + 1, y - 1) respectively.

    -

    Running a vertical line from x = -∞ to x = +∞, whenever the vertical line touches some nodes, we report the values of the nodes in order from top to bottom (decreasing y coordinates).

    +

    The vertical order traversal of a binary tree is a list of non-empty reports for each unique x-coordinate from left to right. Each report is a list of all nodes at a given x-coordinate. The report should be primarily sorted by y-coordinate from highest y-coordinate to lowest. If any two nodes have the same y-coordinate in the report, the node with the smaller value should appear earlier.

    -

    If two nodes have the same position, then the value of the node that is reported first is the value that is smaller.

    - -

    Return a list of non-empty reports in order of x coordinate. Every report will have a list of values of nodes.

    +

    Return the vertical order traversal of the binary tree.

     

    Example 1:

    @@ -28,9 +26,9 @@ Input: root = [3,9,20,null,null,15,7] Output: [[9],[3,15],[20],[7]] Explanation: Without loss of generality, we can assume the root node is at position (0, 0): -Then, the node with value 9 occurs at position (-1, -1); -The nodes with values 3 and 15 occur at positions (0, 0) and (0, -2); -The node with value 20 occurs at position (1, -1); +The node with value 9 occurs at position (-1, -1). +The nodes with values 3 and 15 occur at positions (0, 0) and (0, -2). +The node with value 20 occurs at position (1, -1). The node with value 7 occurs at position (2, -2).

    Example 2:

    @@ -39,7 +37,7 @@ The node with value 7 occurs at position (2, -2).
    Input: root = [1,2,3,4,5,6,7] Output: [[4],[2],[1,5,6],[3],[7]] Explanation: The node with value 5 and the node with value 6 have the same position according to the given scheme. -However, in the report "[1,5,6]", the node value of 5 comes first since 5 is smaller than 6.
    +However, in the report [1,5,6], the node with value 5 comes first since 5 is smaller than 6.

     

    Constraints:

    diff --git a/problems/walking-robot-simulation/README.md b/problems/walking-robot-simulation/README.md index 4b1ec763f..7a8a80243 100644 --- a/problems/walking-robot-simulation/README.md +++ b/problems/walking-robot-simulation/README.md @@ -11,19 +11,28 @@ ## [874. Walking Robot Simulation (Easy)](https://leetcode.com/problems/walking-robot-simulation "模拟行走机器人") -

    A robot on an infinite grid starts at point (0, 0) and faces north. The robot can receive one of three possible types of commands:

    +

    A robot on an infinite XY-plane starts at point (0, 0) and faces north. The robot can receive one of three possible types of commands:

    • -2: turn left 90 degrees,
    • -1: turn right 90 degrees, or
    • -
    • 1 <= x <= 9: move forward x units
    • +
    • 1 <= k <= 9: move forward k units.

    Some of the grid squares are obstacles. The ith obstacle is at grid point obstacles[i] = (xi, yi).

    If the robot would try to move onto them, the robot stays on the previous grid square instead (but still continues following the rest of the route.)

    -

    Return the square of the maximum Euclidean distance that the robot will be from the origin.

    +

    Return the maximum Euclidean distance that the robot will be from the origin squared (i.e. if the distance is 5, return 25).

    + +

    Note:

    + +
      +
    • North means +Y direction.
    • +
    • East means +X direction.
    • +
    • South means -Y direction.
    • +
    • West means -X direction.
    • +

     

    Example 1:

    @@ -31,7 +40,11 @@
     Input: commands = [4,-1,3], obstacles = []
     Output: 25
    -Explanation: robot will go to (3, 4)
    +Explanation: The robot starts at (0, 0):
    +1. Move north 4 units to (0, 4).
    +2. Turn right.
    +3. Move east 3 units to (3, 4).
    +The furthest point away from the origin is (3, 4), which is 32 + 42 = 25 units away.
     

    Example 2:

    @@ -39,7 +52,13 @@
     Input: commands = [4,-1,4,-2,4], obstacles = [[2,4]]
     Output: 65
    -Explanation: robot will be stuck at (1, 4) before turning left and going to (1, 8)
    +Explanation: The robot starts at (0, 0):
    +1. Move north 4 units to (0, 4).
    +2. Turn right.
    +3. Move east 1 unit and get blocked by the obstacle at (2, 4), robot is at (1, 4).
    +4. Turn left.
    +5. Move north 4 units to (1, 8).
    +The furthest point away from the origin is (1, 8), which is 12 + 82 = 65 units away.
     

     

    @@ -47,7 +66,7 @@
    • 1 <= commands.length <= 104
    • -
    • commands[i] is in the list [-2,-1,1,2,3,4,5,6,7,8,9].
    • +
    • commands[i] is one of the values in the list [-2,-1,1,2,3,4,5,6,7,8,9].
    • 0 <= obstacles.length <= 104
    • -3 * 104 <= xi, yi <= 3 * 104
    • The answer is guaranteed to be less than 231.
    • diff --git a/problems/word-ladder/README.md b/problems/word-ladder/README.md index da04e85e8..980ee23d7 100644 --- a/problems/word-ladder/README.md +++ b/problems/word-ladder/README.md @@ -11,14 +11,16 @@ ## [127. Word Ladder (Hard)](https://leetcode.com/problems/word-ladder "单词接龙") -

      Given two words beginWord and endWord, and a dictionary wordList, return the length of the shortest transformation sequence from beginWord to endWord, such that:

      +

      A transformation sequence from word beginWord to word endWord using a dictionary wordList is a sequence of words such that:

        -
      • Only one letter can be changed at a time.
      • -
      • Each transformed word must exist in the word list.
      • +
      • The first word in the sequence is beginWord.
      • +
      • The last word in the sequence is endWord.
      • +
      • Only one letter is different between each adjacent pair of words in the sequence.
      • +
      • Every word in the sequence is in wordList.
      -

      Return 0 if there is no such transformation sequence.

      +

      Given two words, beginWord and endWord, and a dictionary wordList, return the number of words in the shortest transformation sequence from beginWord to endWord, or 0 if no such sequence exists.

       

      Example 1:

      @@ -26,7 +28,7 @@
       Input: beginWord = "hit", endWord = "cog", wordList = ["hot","dot","dog","lot","log","cog"]
       Output: 5
      -Explanation: As one shortest transformation is "hit" -> "hot" -> "dot" -> "dog" -> "cog", return its length 5.
      +Explanation: One shortest transformation is "hit" -> "hot" -> "dot" -> "dog" -> "cog" with 5 words.
       

      Example 2:

      @@ -34,20 +36,20 @@
       Input: beginWord = "hit", endWord = "cog", wordList = ["hot","dot","dog","lot","log"]
       Output: 0
      -Explanation: The endWord "cog" is not in wordList, therefore no possible transformation.
      +Explanation: The endWord "cog" is not in wordList, therefore there is no possible transformation.
       

       

      Constraints:

        -
      • 1 <= beginWord.length <= 100
      • +
      • 1 <= beginWord.length <= 10
      • endWord.length == beginWord.length
      • 1 <= wordList.length <= 5000
      • -
      • wordList[i].length == beginWord.length
      • -
      • beginWordendWord, and wordList[i] consist of lowercase English letters.
      • -
      • beginWord != endWord
      • -
      • All the strings in wordList are unique.
      • +
      • wordList[i].length == beginWord.length
      • +
      • beginWord, endWord, and wordList[i] consist of lowercase English letters.
      • +
      • beginWord != endWord
      • +
      • All the strings in wordList are unique.
      ### Related Topics diff --git a/problems/word-pattern-ii/README.md b/problems/word-pattern-ii/README.md index 4bb45671f..5e9c20a60 100644 --- a/problems/word-pattern-ii/README.md +++ b/problems/word-pattern-ii/README.md @@ -9,7 +9,7 @@                  [Next >](../nim-game "Nim Game") -## [291. Word Pattern II (Hard)](https://leetcode.com/problems/word-pattern-ii "单词规律 II") +## [291. Word Pattern II (Medium)](https://leetcode.com/problems/word-pattern-ii "单词规律 II")

      Given a pattern and a string str, find if str follows the same pattern.

      diff --git a/problems/word-pattern/README.md b/problems/word-pattern/README.md index abb6d2af3..f5da65655 100644 --- a/problems/word-pattern/README.md +++ b/problems/word-pattern/README.md @@ -61,4 +61,4 @@ ### Similar Questions 1. [Isomorphic Strings](../isomorphic-strings) (Easy) - 1. [Word Pattern II](../word-pattern-ii) (Hard) + 1. [Word Pattern II](../word-pattern-ii) (Medium) diff --git a/readme/1-300.md b/readme/1-300.md index 63d054eac..6d10e1a70 100644 --- a/readme/1-300.md +++ b/readme/1-300.md @@ -88,7 +88,7 @@ LeetCode Problems' Solutions | 16 | [3Sum Closest](https://leetcode.com/problems/3sum-closest "最接近的三数之和") | [Go](../problems/3sum-closest) | Medium | | 17 | [Letter Combinations of a Phone Number](https://leetcode.com/problems/letter-combinations-of-a-phone-number "电话号码的字母组合") | [Go](../problems/letter-combinations-of-a-phone-number) | Medium | | 18 | [4Sum](https://leetcode.com/problems/4sum "四数之和") | [Go](../problems/4sum) | Medium | -| 19 | [Remove Nth Node From End of List](https://leetcode.com/problems/remove-nth-node-from-end-of-list "删除链表的倒数第N个节点") | [Go](../problems/remove-nth-node-from-end-of-list) | Medium | +| 19 | [Remove Nth Node From End of List](https://leetcode.com/problems/remove-nth-node-from-end-of-list "删除链表的倒数第 N 个结点") | [Go](../problems/remove-nth-node-from-end-of-list) | Medium | | 20 | [Valid Parentheses](https://leetcode.com/problems/valid-parentheses "有效的括号") | [Go](../problems/valid-parentheses) | Easy | | 21 | [Merge Two Sorted Lists](https://leetcode.com/problems/merge-two-sorted-lists "合并两个有序链表") | [Go](../problems/merge-two-sorted-lists) | Easy | | 22 | [Generate Parentheses](https://leetcode.com/problems/generate-parentheses "括号生成") | [Go](../problems/generate-parentheses) | Medium | @@ -360,7 +360,7 @@ LeetCode Problems' Solutions | 288 | [Unique Word Abbreviation](https://leetcode.com/problems/unique-word-abbreviation "单词的唯一缩写") 🔒 | [Go](../problems/unique-word-abbreviation) | Medium | | 289 | [Game of Life](https://leetcode.com/problems/game-of-life "生命游戏") | [Go](../problems/game-of-life) | Medium | | 290 | [Word Pattern](https://leetcode.com/problems/word-pattern "单词规律") | [Go](../problems/word-pattern) | Easy | -| 291 | [Word Pattern II](https://leetcode.com/problems/word-pattern-ii "单词规律 II") 🔒 | [Go](../problems/word-pattern-ii) | Hard | +| 291 | [Word Pattern II](https://leetcode.com/problems/word-pattern-ii "单词规律 II") 🔒 | [Go](../problems/word-pattern-ii) | Medium | | 292 | [Nim Game](https://leetcode.com/problems/nim-game "Nim 游戏") | [Go](../problems/nim-game) | Easy | | 293 | [Flip Game](https://leetcode.com/problems/flip-game "翻转游戏") 🔒 | [Go](../problems/flip-game) | Easy | | 294 | [Flip Game II](https://leetcode.com/problems/flip-game-ii "翻转游戏 II") 🔒 | [Go](../problems/flip-game-ii) | Medium | diff --git a/readme/301-600.md b/readme/301-600.md index 026123fec..7e8d51d89 100644 --- a/readme/301-600.md +++ b/readme/301-600.md @@ -108,7 +108,7 @@ LeetCode Problems' Solutions | 336 | [Palindrome Pairs](https://leetcode.com/problems/palindrome-pairs "回文对") | [Go](../problems/palindrome-pairs) | Hard | | 337 | [House Robber III](https://leetcode.com/problems/house-robber-iii "打家劫舍 III") | [Go](../problems/house-robber-iii) | Medium | | 338 | [Counting Bits](https://leetcode.com/problems/counting-bits "比特位计数") | [Go](../problems/counting-bits) | Medium | -| 339 | [Nested List Weight Sum](https://leetcode.com/problems/nested-list-weight-sum "嵌套列表权重和") 🔒 | [Go](../problems/nested-list-weight-sum) | Easy | +| 339 | [Nested List Weight Sum](https://leetcode.com/problems/nested-list-weight-sum "嵌套列表权重和") 🔒 | [Go](../problems/nested-list-weight-sum) | Medium | | 340 | [Longest Substring with At Most K Distinct Characters](https://leetcode.com/problems/longest-substring-with-at-most-k-distinct-characters "至多包含 K 个不同字符的最长子串") 🔒 | [Go](../problems/longest-substring-with-at-most-k-distinct-characters) | Medium | | 341 | [Flatten Nested List Iterator](https://leetcode.com/problems/flatten-nested-list-iterator "扁平化嵌套列表迭代器") | [Go](../problems/flatten-nested-list-iterator) | Medium | | 342 | [Power of Four](https://leetcode.com/problems/power-of-four "4的幂") | [Go](../problems/power-of-four) | Easy | diff --git a/readme/601-900.md b/readme/601-900.md index 4fc035be6..c33491502 100644 --- a/readme/601-900.md +++ b/readme/601-900.md @@ -134,11 +134,11 @@ LeetCode Problems' Solutions | 662 | [Maximum Width of Binary Tree](https://leetcode.com/problems/maximum-width-of-binary-tree "二叉树最大宽度") | [Go](../problems/maximum-width-of-binary-tree) | Medium | | 663 | [Equal Tree Partition](https://leetcode.com/problems/equal-tree-partition "均匀树划分") 🔒 | [Go](../problems/equal-tree-partition) | Medium | | 664 | [Strange Printer](https://leetcode.com/problems/strange-printer "奇怪的打印机") | [Go](../problems/strange-printer) | Hard | -| 665 | [Non-decreasing Array](https://leetcode.com/problems/non-decreasing-array "非递减数列") | [Go](../problems/non-decreasing-array) | Easy | +| 665 | [Non-decreasing Array](https://leetcode.com/problems/non-decreasing-array "非递减数列") | [Go](../problems/non-decreasing-array) | Medium | | 666 | [Path Sum IV](https://leetcode.com/problems/path-sum-iv "路径和 IV") 🔒 | [Go](../problems/path-sum-iv) | Medium | | 667 | [Beautiful Arrangement II](https://leetcode.com/problems/beautiful-arrangement-ii "优美的排列 II") | [Go](../problems/beautiful-arrangement-ii) | Medium | | 668 | [Kth Smallest Number in Multiplication Table](https://leetcode.com/problems/kth-smallest-number-in-multiplication-table "乘法表中第k小的数") | [Go](../problems/kth-smallest-number-in-multiplication-table) | Hard | -| 669 | [Trim a Binary Search Tree](https://leetcode.com/problems/trim-a-binary-search-tree "修剪二叉搜索树") | [Go](../problems/trim-a-binary-search-tree) | Easy | +| 669 | [Trim a Binary Search Tree](https://leetcode.com/problems/trim-a-binary-search-tree "修剪二叉搜索树") | [Go](../problems/trim-a-binary-search-tree) | Medium | | 670 | [Maximum Swap](https://leetcode.com/problems/maximum-swap "最大交换") | [Go](../problems/maximum-swap) | Medium | | 671 | [Second Minimum Node In a Binary Tree](https://leetcode.com/problems/second-minimum-node-in-a-binary-tree "二叉树中第二小的节点") | [Go](../problems/second-minimum-node-in-a-binary-tree) | Easy | | 672 | [Bulb Switcher II](https://leetcode.com/problems/bulb-switcher-ii "灯泡开关 Ⅱ") | [Go](../problems/bulb-switcher-ii) | Medium | diff --git a/readme/901-1200.md b/readme/901-1200.md index 63c050c12..dfd88444f 100644 --- a/readme/901-1200.md +++ b/readme/901-1200.md @@ -156,7 +156,7 @@ LeetCode Problems' Solutions | 984 | [String Without AAA or BBB](https://leetcode.com/problems/string-without-aaa-or-bbb "不含 AAA 或 BBB 的字符串") | [Go](../problems/string-without-aaa-or-bbb) | Medium | | 985 | [Sum of Even Numbers After Queries](https://leetcode.com/problems/sum-of-even-numbers-after-queries "查询后的偶数和") | [Go](../problems/sum-of-even-numbers-after-queries) | Easy | | 986 | [Interval List Intersections](https://leetcode.com/problems/interval-list-intersections "区间列表的交集") | [Go](../problems/interval-list-intersections) | Medium | -| 987 | [Vertical Order Traversal of a Binary Tree](https://leetcode.com/problems/vertical-order-traversal-of-a-binary-tree "二叉树的垂序遍历") | [Go](../problems/vertical-order-traversal-of-a-binary-tree) | Medium | +| 987 | [Vertical Order Traversal of a Binary Tree](https://leetcode.com/problems/vertical-order-traversal-of-a-binary-tree "二叉树的垂序遍历") | [Go](../problems/vertical-order-traversal-of-a-binary-tree) | Hard | | 988 | [Smallest String Starting From Leaf](https://leetcode.com/problems/smallest-string-starting-from-leaf "从叶结点开始的最小字符串") | [Go](../problems/smallest-string-starting-from-leaf) | Medium | | 989 | [Add to Array-Form of Integer](https://leetcode.com/problems/add-to-array-form-of-integer "数组形式的整数加法") | [Go](../problems/add-to-array-form-of-integer) | Easy | | 990 | [Satisfiability of Equality Equations](https://leetcode.com/problems/satisfiability-of-equality-equations "等式方程的可满足性") | [Go](../problems/satisfiability-of-equality-equations) | Medium | @@ -339,7 +339,7 @@ LeetCode Problems' Solutions | 1167 | [Minimum Cost to Connect Sticks](https://leetcode.com/problems/minimum-cost-to-connect-sticks "连接棒材的最低费用") 🔒 | [Go](../problems/minimum-cost-to-connect-sticks) | Medium | | 1168 | [Optimize Water Distribution in a Village](https://leetcode.com/problems/optimize-water-distribution-in-a-village "水资源分配优化") 🔒 | [Go](../problems/optimize-water-distribution-in-a-village) | Hard | | 1169 | [Invalid Transactions](https://leetcode.com/problems/invalid-transactions "查询无效交易") | [Go](../problems/invalid-transactions) | Medium | -| 1170 | [Compare Strings by Frequency of the Smallest Character](https://leetcode.com/problems/compare-strings-by-frequency-of-the-smallest-character "比较字符串最小字母出现频次") | [Go](../problems/compare-strings-by-frequency-of-the-smallest-character) | Easy | +| 1170 | [Compare Strings by Frequency of the Smallest Character](https://leetcode.com/problems/compare-strings-by-frequency-of-the-smallest-character "比较字符串最小字母出现频次") | [Go](../problems/compare-strings-by-frequency-of-the-smallest-character) | Medium | | 1171 | [Remove Zero Sum Consecutive Nodes from Linked List](https://leetcode.com/problems/remove-zero-sum-consecutive-nodes-from-linked-list "从链表中删去总和值为零的连续节点") | [Go](../problems/remove-zero-sum-consecutive-nodes-from-linked-list) | Medium | | 1172 | [Dinner Plate Stacks](https://leetcode.com/problems/dinner-plate-stacks "餐盘栈") | [Go](../problems/dinner-plate-stacks) | Hard | | 1173 | [Immediate Food Delivery I](https://leetcode.com/problems/immediate-food-delivery-i "即时食物配送 I") 🔒 | [MySQL](../problems/immediate-food-delivery-i) | Easy | diff --git a/tag/README.md b/tag/README.md index 44eea5ddf..1da49de17 100644 --- a/tag/README.md +++ b/tag/README.md @@ -22,7 +22,7 @@ | 21 | [Recursion](recursion/README.md) | [递归](https://openset.github.io/tags/recursion/) | | 22 | [Sliding Window](sliding-window/README.md) | [Sliding Window](https://openset.github.io/tags/sliding-window/) | | 23 | [Divide and Conquer](divide-and-conquer/README.md) | [分治算法](https://openset.github.io/tags/divide-and-conquer/) | | 24 | [Trie](trie/README.md) | [字典树](https://openset.github.io/tags/trie/) | | 25 | [Segment Tree](segment-tree/README.md) | [线段树](https://openset.github.io/tags/segment-tree/) | | 26 | [Ordered Map](ordered-map/README.md) | [Ordered Map](https://openset.github.io/tags/ordered-map/) | -| 27 | [Geometry](geometry/README.md) | [几何](https://openset.github.io/tags/geometry/) | | 28 | [Queue](queue/README.md) | [队列](https://openset.github.io/tags/queue/) | +| 27 | [Queue](queue/README.md) | [队列](https://openset.github.io/tags/queue/) | | 28 | [Geometry](geometry/README.md) | [几何](https://openset.github.io/tags/geometry/) | | 29 | [Minimax](minimax/README.md) | [极小化极大](https://openset.github.io/tags/minimax/) | | 30 | [Binary Indexed Tree](binary-indexed-tree/README.md) | [树状数组](https://openset.github.io/tags/binary-indexed-tree/) | | 31 | [Brainteaser](brainteaser/README.md) | [脑筋急转弯](https://openset.github.io/tags/brainteaser/) | | 32 | [Line Sweep](line-sweep/README.md) | [Line Sweep](https://openset.github.io/tags/line-sweep/) | | 33 | [Random](random/README.md) | [Random](https://openset.github.io/tags/random/) | | 34 | [Topological Sort](topological-sort/README.md) | [拓扑排序](https://openset.github.io/tags/topological-sort/) | diff --git a/tag/array/README.md b/tag/array/README.md index 2aff55126..edac25008 100644 --- a/tag/array/README.md +++ b/tag/array/README.md @@ -9,8 +9,12 @@ | # | 题目 | 标签 | 难度 | | :-: | - | - | :-: | +| 1738 | [找出第 K 大的异或坐标值](../../problems/find-kth-largest-xor-coordinate-value) | [[数组](../array/README.md)] | Medium | +| 1733 | [需要教语言的最少人数](../../problems/minimum-number-of-people-to-teach) | [[贪心算法](../greedy/README.md)] [[数组](../array/README.md)] | Medium | +| 1732 | [找到最高海拔](../../problems/find-the-highest-altitude) | [[数组](../array/README.md)] | Easy | +| 1726 | [同积元组](../../problems/tuple-with-same-product) | [[数组](../array/README.md)] [[哈希表](../hash-table/README.md)] | Medium | | 1711 | [大餐计数](../../problems/count-good-meals) | [[数组](../array/README.md)] [[哈希表](../hash-table/README.md)] [[双指针](../two-pointers/README.md)] | Medium | -| 1708 | [Largest Subarray Length K](../../problems/largest-subarray-length-k) 🔒 | [[贪心算法](../greedy/README.md)] [[数组](../array/README.md)] | Easy | +| 1708 | [长度为 K 的最大子数组](../../problems/largest-subarray-length-k) 🔒 | [[贪心算法](../greedy/README.md)] [[数组](../array/README.md)] | Easy | | 1701 | [平均等待时间](../../problems/average-waiting-time) | [[数组](../array/README.md)] | Medium | | 1700 | [无法吃午餐的学生数量](../../problems/number-of-students-unable-to-eat-lunch) | [[数组](../array/README.md)] | Easy | | 1672 | [最富有客户的资产总量](../../problems/richest-customer-wealth) | [[数组](../array/README.md)] | Easy | @@ -62,7 +66,7 @@ | 1450 | [在既定时间做作业的学生人数](../../problems/number-of-students-doing-homework-at-a-given-time) | [[数组](../array/README.md)] | Easy | | 1442 | [形成两个异或相等数组的三元组数目](../../problems/count-triplets-that-can-form-two-arrays-of-equal-xor) | [[位运算](../bit-manipulation/README.md)] [[数组](../array/README.md)] [[数学](../math/README.md)] | Medium | | 1438 | [绝对差不超过限制的最长连续子数组](../../problems/longest-continuous-subarray-with-absolute-diff-less-than-or-equal-to-limit) | [[数组](../array/README.md)] [[Sliding Window](../sliding-window/README.md)] | Medium | -| 1437 | [是否所有 1 都至少相隔 k 个元素](../../problems/check-if-all-1s-are-at-least-length-k-places-away) | [[数组](../array/README.md)] | Medium | +| 1437 | [是否所有 1 都至少相隔 k 个元素](../../problems/check-if-all-1s-are-at-least-length-k-places-away) | [[数组](../array/README.md)] | Easy | | 1431 | [拥有最多糖果的孩子](../../problems/kids-with-the-greatest-number-of-candies) | [[数组](../array/README.md)] | Easy | | 1428 | [至少有一个 1 的最左端列](../../problems/leftmost-column-with-at-least-a-one) 🔒 | [[数组](../array/README.md)] | Medium | | 1427 | [字符串的左右移](../../problems/perform-string-shifts) 🔒 | [[数组](../array/README.md)] [[数学](../math/README.md)] | Easy | @@ -118,7 +122,7 @@ | 1184 | [公交站间的距离](../../problems/distance-between-bus-stops) | [[数组](../array/README.md)] | Easy | | 1177 | [构建回文串检测](../../problems/can-make-palindrome-from-substring) | [[数组](../array/README.md)] [[字符串](../string/README.md)] | Medium | | 1176 | [健身计划评估](../../problems/diet-plan-performance) 🔒 | [[数组](../array/README.md)] [[Sliding Window](../sliding-window/README.md)] | Easy | -| 1170 | [比较字符串最小字母出现频次](../../problems/compare-strings-by-frequency-of-the-smallest-character) | [[数组](../array/README.md)] [[字符串](../string/README.md)] | Easy | +| 1170 | [比较字符串最小字母出现频次](../../problems/compare-strings-by-frequency-of-the-smallest-character) | [[数组](../array/README.md)] [[字符串](../string/README.md)] [[二分查找](../binary-search/README.md)] | Medium | | 1169 | [查询无效交易](../../problems/invalid-transactions) | [[数组](../array/README.md)] [[字符串](../string/README.md)] | Medium | | 1160 | [拼写单词](../../problems/find-words-that-can-be-formed-by-characters) | [[数组](../array/README.md)] [[哈希表](../hash-table/README.md)] | Easy | | 1157 | [子数组中占绝大多数的元素](../../problems/online-majority-element-in-subarray) | [[线段树](../segment-tree/README.md)] [[数组](../array/README.md)] [[二分查找](../binary-search/README.md)] | Hard | @@ -254,7 +258,7 @@ | 189 | [旋转数组](../../problems/rotate-array) | [[数组](../array/README.md)] | Medium | | 169 | [多数元素](../../problems/majority-element) | [[位运算](../bit-manipulation/README.md)] [[数组](../array/README.md)] [[分治算法](../divide-and-conquer/README.md)] | Easy | | 167 | [两数之和 II - 输入有序数组](../../problems/two-sum-ii-input-array-is-sorted) | [[数组](../array/README.md)] [[双指针](../two-pointers/README.md)] [[二分查找](../binary-search/README.md)] | Easy | -| 163 | [缺失的区间](../../problems/missing-ranges) 🔒 | [[数组](../array/README.md)] | Medium | +| 163 | [缺失的区间](../../problems/missing-ranges) 🔒 | [[数组](../array/README.md)] | Easy | | 162 | [寻找峰值](../../problems/find-peak-element) | [[数组](../array/README.md)] [[二分查找](../binary-search/README.md)] | Medium | | 154 | [寻找旋转排序数组中的最小值 II](../../problems/find-minimum-in-rotated-sorted-array-ii) | [[数组](../array/README.md)] [[二分查找](../binary-search/README.md)] | Hard | | 153 | [寻找旋转排序数组中的最小值](../../problems/find-minimum-in-rotated-sorted-array) | [[数组](../array/README.md)] [[二分查找](../binary-search/README.md)] | Medium | @@ -285,14 +289,14 @@ | 63 | [不同路径 II](../../problems/unique-paths-ii) | [[数组](../array/README.md)] [[动态规划](../dynamic-programming/README.md)] | Medium | | 62 | [不同路径](../../problems/unique-paths) | [[数组](../array/README.md)] [[动态规划](../dynamic-programming/README.md)] | Medium | | 59 | [螺旋矩阵 II](../../problems/spiral-matrix-ii) | [[数组](../array/README.md)] | Medium | -| 57 | [插入区间](../../problems/insert-interval) | [[排序](../sort/README.md)] [[数组](../array/README.md)] | Hard | +| 57 | [插入区间](../../problems/insert-interval) | [[排序](../sort/README.md)] [[数组](../array/README.md)] | Medium | | 56 | [合并区间](../../problems/merge-intervals) | [[排序](../sort/README.md)] [[数组](../array/README.md)] | Medium | | 55 | [跳跃游戏](../../problems/jump-game) | [[贪心算法](../greedy/README.md)] [[数组](../array/README.md)] | Medium | | 54 | [螺旋矩阵](../../problems/spiral-matrix) | [[数组](../array/README.md)] | Medium | | 53 | [最大子序和](../../problems/maximum-subarray) | [[数组](../array/README.md)] [[分治算法](../divide-and-conquer/README.md)] [[动态规划](../dynamic-programming/README.md)] | Easy | | 48 | [旋转图像](../../problems/rotate-image) | [[数组](../array/README.md)] | Medium | | 45 | [跳跃游戏 II](../../problems/jump-game-ii) | [[贪心算法](../greedy/README.md)] [[数组](../array/README.md)] | Hard | -| 42 | [接雨水](../../problems/trapping-rain-water) | [[栈](../stack/README.md)] [[数组](../array/README.md)] [[双指针](../two-pointers/README.md)] | Hard | +| 42 | [接雨水](../../problems/trapping-rain-water) | [[栈](../stack/README.md)] [[数组](../array/README.md)] [[双指针](../two-pointers/README.md)] [[动态规划](../dynamic-programming/README.md)] | Hard | | 41 | [缺失的第一个正数](../../problems/first-missing-positive) | [[数组](../array/README.md)] | Hard | | 40 | [组合总和 II](../../problems/combination-sum-ii) | [[数组](../array/README.md)] [[回溯算法](../backtracking/README.md)] | Medium | | 39 | [组合总和](../../problems/combination-sum) | [[数组](../array/README.md)] [[回溯算法](../backtracking/README.md)] | Medium | diff --git a/tag/backtracking/README.md b/tag/backtracking/README.md index 3d7addb8b..f25f28a74 100644 --- a/tag/backtracking/README.md +++ b/tag/backtracking/README.md @@ -48,12 +48,12 @@ | 320 | [列举单词的全部缩写](../../problems/generalized-abbreviation) 🔒 | [[位运算](../bit-manipulation/README.md)] [[回溯算法](../backtracking/README.md)] | Medium | | 306 | [累加数](../../problems/additive-number) | [[回溯算法](../backtracking/README.md)] | Medium | | 294 | [翻转游戏 II](../../problems/flip-game-ii) 🔒 | [[极小化极大](../minimax/README.md)] [[回溯算法](../backtracking/README.md)] | Medium | -| 291 | [单词规律 II](../../problems/word-pattern-ii) 🔒 | [[回溯算法](../backtracking/README.md)] | Hard | +| 291 | [单词规律 II](../../problems/word-pattern-ii) 🔒 | [[回溯算法](../backtracking/README.md)] | Medium | | 267 | [回文排列 II](../../problems/palindrome-permutation-ii) 🔒 | [[回溯算法](../backtracking/README.md)] | Medium | | 254 | [因子的组合](../../problems/factor-combinations) 🔒 | [[回溯算法](../backtracking/README.md)] | Medium | | 216 | [组合总和 III](../../problems/combination-sum-iii) | [[数组](../array/README.md)] [[回溯算法](../backtracking/README.md)] | Medium | | 212 | [单词搜索 II](../../problems/word-search-ii) | [[字典树](../trie/README.md)] [[回溯算法](../backtracking/README.md)] | Hard | -| 211 | [添加与搜索单词 - 数据结构设计](../../problems/design-add-and-search-words-data-structure) | [[设计](../design/README.md)] [[字典树](../trie/README.md)] [[回溯算法](../backtracking/README.md)] | Medium | +| 211 | [添加与搜索单词 - 数据结构设计](../../problems/design-add-and-search-words-data-structure) | [[深度优先搜索](../depth-first-search/README.md)] [[设计](../design/README.md)] [[字典树](../trie/README.md)] [[回溯算法](../backtracking/README.md)] | Medium | | 140 | [单词拆分 II](../../problems/word-break-ii) | [[动态规划](../dynamic-programming/README.md)] [[回溯算法](../backtracking/README.md)] | Hard | | 131 | [分割回文串](../../problems/palindrome-partitioning) | [[深度优先搜索](../depth-first-search/README.md)] [[动态规划](../dynamic-programming/README.md)] [[回溯算法](../backtracking/README.md)] | Medium | | 126 | [单词接龙 II](../../problems/word-ladder-ii) | [[广度优先搜索](../breadth-first-search/README.md)] [[数组](../array/README.md)] [[字符串](../string/README.md)] [[回溯算法](../backtracking/README.md)] | Hard | diff --git a/tag/binary-indexed-tree/README.md b/tag/binary-indexed-tree/README.md index c899b2671..0beece97f 100644 --- a/tag/binary-indexed-tree/README.md +++ b/tag/binary-indexed-tree/README.md @@ -9,3 +9,10 @@ | # | 题目 | 标签 | 难度 | | :-: | - | - | :-: | +| 1649 | [通过指令创建有序数组](../../problems/create-sorted-array-through-instructions) | [[树状数组](../binary-indexed-tree/README.md)] [[线段树](../segment-tree/README.md)] [[二分查找](../binary-search/README.md)] [[Ordered Map](../ordered-map/README.md)] | Hard | +| 493 | [翻转对](../../problems/reverse-pairs) | [[排序](../sort/README.md)] [[树状数组](../binary-indexed-tree/README.md)] [[线段树](../segment-tree/README.md)] [[二分查找](../binary-search/README.md)] [[分治算法](../divide-and-conquer/README.md)] | Hard | +| 327 | [区间和的个数](../../problems/count-of-range-sum) | [[排序](../sort/README.md)] [[树状数组](../binary-indexed-tree/README.md)] [[线段树](../segment-tree/README.md)] [[二分查找](../binary-search/README.md)] [[分治算法](../divide-and-conquer/README.md)] | Hard | +| 315 | [计算右侧小于当前元素的个数](../../problems/count-of-smaller-numbers-after-self) | [[排序](../sort/README.md)] [[树状数组](../binary-indexed-tree/README.md)] [[线段树](../segment-tree/README.md)] [[二分查找](../binary-search/README.md)] [[分治算法](../divide-and-conquer/README.md)] | Hard | +| 308 | [二维区域和检索 - 可变](../../problems/range-sum-query-2d-mutable) 🔒 | [[树状数组](../binary-indexed-tree/README.md)] [[线段树](../segment-tree/README.md)] | Hard | +| 307 | [区域和检索 - 数组可修改](../../problems/range-sum-query-mutable) | [[树状数组](../binary-indexed-tree/README.md)] [[线段树](../segment-tree/README.md)] | Medium | +| 218 | [天际线问题](../../problems/the-skyline-problem) | [[堆](../heap/README.md)] [[树状数组](../binary-indexed-tree/README.md)] [[线段树](../segment-tree/README.md)] [[分治算法](../divide-and-conquer/README.md)] [[Line Sweep](../line-sweep/README.md)] | Hard | diff --git a/tag/binary-search-tree/README.md b/tag/binary-search-tree/README.md index 43b103e11..0d508d4e1 100644 --- a/tag/binary-search-tree/README.md +++ b/tag/binary-search-tree/README.md @@ -9,3 +9,7 @@ | # | 题目 | 标签 | 难度 | | :-: | - | - | :-: | +| 1382 | [将二叉搜索树变平衡](../../problems/balance-a-binary-search-tree) | [[二叉搜索树](../binary-search-tree/README.md)] | Medium | +| 1373 | [二叉搜索子树的最大键值和](../../problems/maximum-sum-bst-in-binary-tree) | [[二叉搜索树](../binary-search-tree/README.md)] [[动态规划](../dynamic-programming/README.md)] | Hard | +| 1214 | [查找两棵二叉搜索树之和](../../problems/two-sum-bsts) 🔒 | [[二叉搜索树](../binary-search-tree/README.md)] | Medium | +| 1038 | [把二叉搜索树转换为累加树](../../problems/binary-search-tree-to-greater-sum-tree) | [[二叉搜索树](../binary-search-tree/README.md)] | Medium | diff --git a/tag/binary-search/README.md b/tag/binary-search/README.md index 6379fffed..31963f6d8 100644 --- a/tag/binary-search/README.md +++ b/tag/binary-search/README.md @@ -9,8 +9,9 @@ | # | 题目 | 标签 | 难度 | | :-: | - | - | :-: | +| 1739 | [放置盒子](../../problems/building-boxes) | [[数学](../math/README.md)] [[二分查找](../binary-search/README.md)] | Hard | | 1712 | [将数组分成三个子数组的方案数](../../problems/ways-to-split-array-into-three-subarrays) | [[双指针](../two-pointers/README.md)] [[二分查找](../binary-search/README.md)] | Medium | -| 1658 | [将 x 减到 0 的最小操作数](../../problems/minimum-operations-to-reduce-x-to-zero) | [[贪心算法](../greedy/README.md)] [[双指针](../two-pointers/README.md)] [[二分查找](../binary-search/README.md)] | Medium | +| 1658 | [将 x 减到 0 的最小操作数](../../problems/minimum-operations-to-reduce-x-to-zero) | [[贪心算法](../greedy/README.md)] [[双指针](../two-pointers/README.md)] [[二分查找](../binary-search/README.md)] [[Sliding Window](../sliding-window/README.md)] | Medium | | 1649 | [通过指令创建有序数组](../../problems/create-sorted-array-through-instructions) | [[树状数组](../binary-indexed-tree/README.md)] [[线段树](../segment-tree/README.md)] [[二分查找](../binary-search/README.md)] [[Ordered Map](../ordered-map/README.md)] | Hard | | 1642 | [可以到达的最远建筑](../../problems/furthest-building-you-can-reach) | [[堆](../heap/README.md)] [[二分查找](../binary-search/README.md)] | Medium | | 1631 | [最小体力消耗路径](../../problems/path-with-minimum-effort) | [[深度优先搜索](../depth-first-search/README.md)] [[并查集](../union-find/README.md)] [[图](../graph/README.md)] [[二分查找](../binary-search/README.md)] | Medium | @@ -27,12 +28,13 @@ | 1300 | [转变数组后最接近目标值的数组和](../../problems/sum-of-mutated-array-closest-to-target) | [[数组](../array/README.md)] [[二分查找](../binary-search/README.md)] | Medium | | 1292 | [元素和小于等于阈值的正方形的最大边长](../../problems/maximum-side-length-of-a-square-with-sum-less-than-or-equal-to-threshold) | [[数组](../array/README.md)] [[二分查找](../binary-search/README.md)] | Medium | | 1283 | [使结果不超过阈值的最小除数](../../problems/find-the-smallest-divisor-given-a-threshold) | [[二分查找](../binary-search/README.md)] | Medium | -| 1237 | [找出给定方程的正整数解](../../problems/find-positive-integer-solution-for-a-given-equation) | [[数学](../math/README.md)] [[二分查找](../binary-search/README.md)] | Easy | +| 1237 | [找出给定方程的正整数解](../../problems/find-positive-integer-solution-for-a-given-equation) | [[数学](../math/README.md)] [[二分查找](../binary-search/README.md)] | Medium | | 1235 | [规划兼职工作](../../problems/maximum-profit-in-job-scheduling) | [[排序](../sort/README.md)] [[二分查找](../binary-search/README.md)] [[动态规划](../dynamic-programming/README.md)] | Hard | | 1231 | [分享巧克力](../../problems/divide-chocolate) 🔒 | [[贪心算法](../greedy/README.md)] [[二分查找](../binary-search/README.md)] | Hard | | 1201 | [丑数 III](../../problems/ugly-number-iii) | [[数学](../math/README.md)] [[二分查找](../binary-search/README.md)] | Medium | | 1198 | [找出所有行中最小公共元素](../../problems/find-smallest-common-element-in-all-rows) 🔒 | [[哈希表](../hash-table/README.md)] [[二分查找](../binary-search/README.md)] | Medium | | 1182 | [与目标颜色间的最短距离](../../problems/shortest-distance-to-target-color) 🔒 | [[二分查找](../binary-search/README.md)] | Medium | +| 1170 | [比较字符串最小字母出现频次](../../problems/compare-strings-by-frequency-of-the-smallest-character) | [[数组](../array/README.md)] [[字符串](../string/README.md)] [[二分查找](../binary-search/README.md)] | Medium | | 1157 | [子数组中占绝大多数的元素](../../problems/online-majority-element-in-subarray) | [[线段树](../segment-tree/README.md)] [[数组](../array/README.md)] [[二分查找](../binary-search/README.md)] | Hard | | 1150 | [检查一个数是否在数组中占绝大多数](../../problems/check-if-a-number-is-majority-element-in-a-sorted-array) 🔒 | [[数组](../array/README.md)] [[二分查找](../binary-search/README.md)] | Easy | | 1111 | [有效括号的嵌套深度](../../problems/maximum-nesting-depth-of-two-valid-parentheses-strings) | [[贪心算法](../greedy/README.md)] [[二分查找](../binary-search/README.md)] | Medium | diff --git a/tag/bit-manipulation/README.md b/tag/bit-manipulation/README.md index 88d28a8bc..864999c74 100644 --- a/tag/bit-manipulation/README.md +++ b/tag/bit-manipulation/README.md @@ -9,6 +9,7 @@ | # | 题目 | 标签 | 难度 | | :-: | - | - | :-: | +| 1734 | [解码异或后的排列](../../problems/decode-xored-permutation) | [[位运算](../bit-manipulation/README.md)] | Medium | | 1720 | [解码异或后的数组](../../problems/decode-xored-array) | [[位运算](../bit-manipulation/README.md)] | Easy | | 1707 | [与数组中元素的最大异或值](../../problems/maximum-xor-with-an-element-from-array) | [[位运算](../bit-manipulation/README.md)] [[字典树](../trie/README.md)] | Hard | | 1611 | [使整数变为 0 的最少操作次数](../../problems/minimum-one-bit-operations-to-make-integers-zero) | [[位运算](../bit-manipulation/README.md)] [[动态规划](../dynamic-programming/README.md)] | Hard | diff --git a/tag/breadth-first-search/README.md b/tag/breadth-first-search/README.md index e5a4936b5..97922c717 100644 --- a/tag/breadth-first-search/README.md +++ b/tag/breadth-first-search/README.md @@ -9,81 +9,3 @@ | # | 题目 | 标签 | 难度 | | :-: | - | - | :-: | -| 1654 | [到家的最少跳跃次数](../../problems/minimum-jumps-to-reach-home) | [[广度优先搜索](../breadth-first-search/README.md)] [[动态规划](../dynamic-programming/README.md)] | Medium | -| 1625 | [执行操作后字典序最小的字符串](../../problems/lexicographically-smallest-string-after-applying-operations) | [[深度优先搜索](../depth-first-search/README.md)] [[广度优先搜索](../breadth-first-search/README.md)] | Medium | -| 1602 | [找到二叉树中最近的右侧节点](../../problems/find-nearest-right-node-in-binary-tree) 🔒 | [[树](../tree/README.md)] [[广度优先搜索](../breadth-first-search/README.md)] | Medium | -| 1519 | [子树中标签相同的节点数](../../problems/number-of-nodes-in-the-sub-tree-with-the-same-label) | [[深度优先搜索](../depth-first-search/README.md)] [[广度优先搜索](../breadth-first-search/README.md)] | Medium | -| 1490 | [克隆 N 叉树](../../problems/clone-n-ary-tree) 🔒 | [[树](../tree/README.md)] [[深度优先搜索](../depth-first-search/README.md)] [[广度优先搜索](../breadth-first-search/README.md)] [[哈希表](../hash-table/README.md)] | Medium | -| 1391 | [检查网格中是否存在有效路径](../../problems/check-if-there-is-a-valid-path-in-a-grid) | [[深度优先搜索](../depth-first-search/README.md)] [[广度优先搜索](../breadth-first-search/README.md)] | Medium | -| 1379 | [找出克隆二叉树中的相同节点](../../problems/find-a-corresponding-node-of-a-binary-tree-in-a-clone-of-that-tree) | [[树](../tree/README.md)] [[深度优先搜索](../depth-first-search/README.md)] [[广度优先搜索](../breadth-first-search/README.md)] [[递归](../recursion/README.md)] | Medium | -| 1368 | [使网格图至少有一条有效路径的最小代价](../../problems/minimum-cost-to-make-at-least-one-valid-path-in-a-grid) | [[广度优先搜索](../breadth-first-search/README.md)] | Hard | -| 1345 | [跳跃游戏 IV](../../problems/jump-game-iv) | [[广度优先搜索](../breadth-first-search/README.md)] | Hard | -| 1319 | [连通网络的操作次数](../../problems/number-of-operations-to-make-network-connected) | [[深度优先搜索](../depth-first-search/README.md)] [[广度优先搜索](../breadth-first-search/README.md)] [[并查集](../union-find/README.md)] | Medium | -| 1311 | [获取你好友已观看的视频](../../problems/get-watched-videos-by-your-friends) | [[广度优先搜索](../breadth-first-search/README.md)] [[哈希表](../hash-table/README.md)] [[字符串](../string/README.md)] | Medium | -| 1306 | [跳跃游戏 III](../../problems/jump-game-iii) | [[深度优先搜索](../depth-first-search/README.md)] [[广度优先搜索](../breadth-first-search/README.md)] [[递归](../recursion/README.md)] | Medium | -| 1298 | [你能从盒子里获得的最大糖果数](../../problems/maximum-candies-you-can-get-from-boxes) | [[广度优先搜索](../breadth-first-search/README.md)] | Hard | -| 1293 | [网格中的最短路径](../../problems/shortest-path-in-a-grid-with-obstacles-elimination) | [[广度优先搜索](../breadth-first-search/README.md)] | Hard | -| 1284 | [转化为全零矩阵的最少反转次数](../../problems/minimum-number-of-flips-to-convert-binary-matrix-to-zero-matrix) | [[广度优先搜索](../breadth-first-search/README.md)] | Hard | -| 1263 | [推箱子](../../problems/minimum-moves-to-move-a-box-to-their-target-location) | [[广度优先搜索](../breadth-first-search/README.md)] | Hard | -| 1245 | [树的直径](../../problems/tree-diameter) 🔒 | [[树](../tree/README.md)] [[深度优先搜索](../depth-first-search/README.md)] [[广度优先搜索](../breadth-first-search/README.md)] | Medium | -| 1242 | [多线程网页爬虫](../../problems/web-crawler-multithreaded) 🔒 | [[深度优先搜索](../depth-first-search/README.md)] [[广度优先搜索](../breadth-first-search/README.md)] | Medium | -| 1236 | [网络爬虫](../../problems/web-crawler) 🔒 | [[深度优先搜索](../depth-first-search/README.md)] [[广度优先搜索](../breadth-first-search/README.md)] | Medium | -| 1210 | [穿过迷宫的最少移动次数](../../problems/minimum-moves-to-reach-target-with-rotations) | [[广度优先搜索](../breadth-first-search/README.md)] | Hard | -| 1197 | [进击的骑士](../../problems/minimum-knight-moves) 🔒 | [[广度优先搜索](../breadth-first-search/README.md)] | Medium | -| 1162 | [地图分析](../../problems/as-far-from-land-as-possible) | [[广度优先搜索](../breadth-first-search/README.md)] [[图](../graph/README.md)] | Medium | -| 1161 | [最大层内元素和](../../problems/maximum-level-sum-of-a-binary-tree) | [[树](../tree/README.md)] [[广度优先搜索](../breadth-first-search/README.md)] | Medium | -| 1129 | [颜色交替的最短路径](../../problems/shortest-path-with-alternating-colors) | [[广度优先搜索](../breadth-first-search/README.md)] [[图](../graph/README.md)] | Medium | -| 1091 | [二进制矩阵中的最短路径](../../problems/shortest-path-in-binary-matrix) | [[广度优先搜索](../breadth-first-search/README.md)] | Medium | -| 1036 | [逃离大迷宫](../../problems/escape-a-large-maze) | [[广度优先搜索](../breadth-first-search/README.md)] | Hard | -| 994 | [腐烂的橘子](../../problems/rotting-oranges) | [[广度优先搜索](../breadth-first-search/README.md)] | Medium | -| 993 | [二叉树的堂兄弟节点](../../problems/cousins-in-binary-tree) | [[树](../tree/README.md)] [[广度优先搜索](../breadth-first-search/README.md)] | Easy | -| 967 | [连续差相同的数字](../../problems/numbers-with-same-consecutive-differences) | [[深度优先搜索](../depth-first-search/README.md)] [[广度优先搜索](../breadth-first-search/README.md)] [[递归](../recursion/README.md)] [[回溯算法](../backtracking/README.md)] | Medium | -| 934 | [最短的桥](../../problems/shortest-bridge) | [[深度优先搜索](../depth-first-search/README.md)] [[广度优先搜索](../breadth-first-search/README.md)] | Medium | -| 913 | [猫和老鼠](../../problems/cat-and-mouse) | [[广度优先搜索](../breadth-first-search/README.md)] [[极小化极大](../minimax/README.md)] | Hard | -| 909 | [蛇梯棋](../../problems/snakes-and-ladders) | [[广度优先搜索](../breadth-first-search/README.md)] | Medium | -| 865 | [具有所有最深节点的最小子树](../../problems/smallest-subtree-with-all-the-deepest-nodes) | [[树](../tree/README.md)] [[深度优先搜索](../depth-first-search/README.md)] [[广度优先搜索](../breadth-first-search/README.md)] [[递归](../recursion/README.md)] | Medium | -| 864 | [获取所有钥匙的最短路径](../../problems/shortest-path-to-get-all-keys) | [[堆](../heap/README.md)] [[广度优先搜索](../breadth-first-search/README.md)] | Hard | -| 863 | [二叉树中所有距离为 K 的结点](../../problems/all-nodes-distance-k-in-binary-tree) | [[树](../tree/README.md)] [[深度优先搜索](../depth-first-search/README.md)] [[广度优先搜索](../breadth-first-search/README.md)] | Medium | -| 854 | [相似度为 K 的字符串](../../problems/k-similar-strings) | [[广度优先搜索](../breadth-first-search/README.md)] [[图](../graph/README.md)] | Hard | -| 847 | [访问所有节点的最短路径](../../problems/shortest-path-visiting-all-nodes) | [[广度优先搜索](../breadth-first-search/README.md)] [[动态规划](../dynamic-programming/README.md)] | Hard | -| 815 | [公交路线](../../problems/bus-routes) | [[广度优先搜索](../breadth-first-search/README.md)] | Hard | -| 787 | [K 站中转内最便宜的航班](../../problems/cheapest-flights-within-k-stops) | [[堆](../heap/README.md)] [[广度优先搜索](../breadth-first-search/README.md)] [[动态规划](../dynamic-programming/README.md)] | Medium | -| 785 | [判断二分图](../../problems/is-graph-bipartite) | [[深度优先搜索](../depth-first-search/README.md)] [[广度优先搜索](../breadth-first-search/README.md)] [[图](../graph/README.md)] | Medium | -| 773 | [滑动谜题](../../problems/sliding-puzzle) | [[广度优先搜索](../breadth-first-search/README.md)] | Hard | -| 752 | [打开转盘锁](../../problems/open-the-lock) | [[广度优先搜索](../breadth-first-search/README.md)] | Medium | -| 743 | [网络延迟时间](../../problems/network-delay-time) | [[堆](../heap/README.md)] [[深度优先搜索](../depth-first-search/README.md)] [[广度优先搜索](../breadth-first-search/README.md)] [[图](../graph/README.md)] | Medium | -| 690 | [员工的重要性](../../problems/employee-importance) | [[深度优先搜索](../depth-first-search/README.md)] [[广度优先搜索](../breadth-first-search/README.md)] [[哈希表](../hash-table/README.md)] | Easy | -| 675 | [为高尔夫比赛砍树](../../problems/cut-off-trees-for-golf-event) | [[广度优先搜索](../breadth-first-search/README.md)] | Hard | -| 559 | [N 叉树的最大深度](../../problems/maximum-depth-of-n-ary-tree) | [[树](../tree/README.md)] [[深度优先搜索](../depth-first-search/README.md)] [[广度优先搜索](../breadth-first-search/README.md)] | Easy | -| 542 | [01 矩阵](../../problems/01-matrix) | [[深度优先搜索](../depth-first-search/README.md)] [[广度优先搜索](../breadth-first-search/README.md)] | Medium | -| 529 | [扫雷游戏](../../problems/minesweeper) | [[深度优先搜索](../depth-first-search/README.md)] [[广度优先搜索](../breadth-first-search/README.md)] | Medium | -| 515 | [在每个树行中找最大值](../../problems/find-largest-value-in-each-tree-row) | [[树](../tree/README.md)] [[深度优先搜索](../depth-first-search/README.md)] [[广度优先搜索](../breadth-first-search/README.md)] | Medium | -| 513 | [找树左下角的值](../../problems/find-bottom-left-tree-value) | [[树](../tree/README.md)] [[深度优先搜索](../depth-first-search/README.md)] [[广度优先搜索](../breadth-first-search/README.md)] | Medium | -| 505 | [迷宫 II](../../problems/the-maze-ii) 🔒 | [[深度优先搜索](../depth-first-search/README.md)] [[广度优先搜索](../breadth-first-search/README.md)] | Medium | -| 499 | [迷宫 III](../../problems/the-maze-iii) 🔒 | [[深度优先搜索](../depth-first-search/README.md)] [[广度优先搜索](../breadth-first-search/README.md)] | Hard | -| 490 | [迷宫](../../problems/the-maze) 🔒 | [[深度优先搜索](../depth-first-search/README.md)] [[广度优先搜索](../breadth-first-search/README.md)] | Medium | -| 429 | [N 叉树的层序遍历](../../problems/n-ary-tree-level-order-traversal) | [[树](../tree/README.md)] [[广度优先搜索](../breadth-first-search/README.md)] | Medium | -| 417 | [太平洋大西洋水流问题](../../problems/pacific-atlantic-water-flow) | [[深度优先搜索](../depth-first-search/README.md)] [[广度优先搜索](../breadth-first-search/README.md)] | Medium | -| 407 | [接雨水 II](../../problems/trapping-rain-water-ii) | [[堆](../heap/README.md)] [[广度优先搜索](../breadth-first-search/README.md)] | Hard | -| 323 | [无向图中连通分量的数目](../../problems/number-of-connected-components-in-an-undirected-graph) 🔒 | [[深度优先搜索](../depth-first-search/README.md)] [[广度优先搜索](../breadth-first-search/README.md)] [[并查集](../union-find/README.md)] [[图](../graph/README.md)] | Medium | -| 317 | [离建筑物最近的距离](../../problems/shortest-distance-from-all-buildings) 🔒 | [[广度优先搜索](../breadth-first-search/README.md)] | Hard | -| 314 | [二叉树的垂直遍历](../../problems/binary-tree-vertical-order-traversal) 🔒 | [[深度优先搜索](../depth-first-search/README.md)] [[广度优先搜索](../breadth-first-search/README.md)] | Medium | -| 310 | [最小高度树](../../problems/minimum-height-trees) | [[广度优先搜索](../breadth-first-search/README.md)] [[图](../graph/README.md)] | Medium | -| 301 | [删除无效的括号](../../problems/remove-invalid-parentheses) | [[深度优先搜索](../depth-first-search/README.md)] [[广度优先搜索](../breadth-first-search/README.md)] | Hard | -| 286 | [墙与门](../../problems/walls-and-gates) 🔒 | [[广度优先搜索](../breadth-first-search/README.md)] | Medium | -| 279 | [完全平方数](../../problems/perfect-squares) | [[广度优先搜索](../breadth-first-search/README.md)] [[数学](../math/README.md)] [[动态规划](../dynamic-programming/README.md)] | Medium | -| 261 | [以图判树](../../problems/graph-valid-tree) 🔒 | [[深度优先搜索](../depth-first-search/README.md)] [[广度优先搜索](../breadth-first-search/README.md)] [[并查集](../union-find/README.md)] [[图](../graph/README.md)] | Medium | -| 210 | [课程表 II](../../problems/course-schedule-ii) | [[深度优先搜索](../depth-first-search/README.md)] [[广度优先搜索](../breadth-first-search/README.md)] [[图](../graph/README.md)] [[拓扑排序](../topological-sort/README.md)] | Medium | -| 207 | [课程表](../../problems/course-schedule) | [[深度优先搜索](../depth-first-search/README.md)] [[广度优先搜索](../breadth-first-search/README.md)] [[图](../graph/README.md)] [[拓扑排序](../topological-sort/README.md)] | Medium | -| 200 | [岛屿数量](../../problems/number-of-islands) | [[深度优先搜索](../depth-first-search/README.md)] [[广度优先搜索](../breadth-first-search/README.md)] [[并查集](../union-find/README.md)] | Medium | -| 199 | [二叉树的右视图](../../problems/binary-tree-right-side-view) | [[树](../tree/README.md)] [[深度优先搜索](../depth-first-search/README.md)] [[广度优先搜索](../breadth-first-search/README.md)] | Medium | -| 133 | [克隆图](../../problems/clone-graph) | [[深度优先搜索](../depth-first-search/README.md)] [[广度优先搜索](../breadth-first-search/README.md)] [[图](../graph/README.md)] | Medium | -| 130 | [被围绕的区域](../../problems/surrounded-regions) | [[深度优先搜索](../depth-first-search/README.md)] [[广度优先搜索](../breadth-first-search/README.md)] [[并查集](../union-find/README.md)] | Medium | -| 127 | [单词接龙](../../problems/word-ladder) | [[广度优先搜索](../breadth-first-search/README.md)] | Hard | -| 126 | [单词接龙 II](../../problems/word-ladder-ii) | [[广度优先搜索](../breadth-first-search/README.md)] [[数组](../array/README.md)] [[字符串](../string/README.md)] [[回溯算法](../backtracking/README.md)] | Hard | -| 116 | [填充每个节点的下一个右侧节点指针](../../problems/populating-next-right-pointers-in-each-node) | [[树](../tree/README.md)] [[深度优先搜索](../depth-first-search/README.md)] [[广度优先搜索](../breadth-first-search/README.md)] | Medium | -| 111 | [二叉树的最小深度](../../problems/minimum-depth-of-binary-tree) | [[树](../tree/README.md)] [[深度优先搜索](../depth-first-search/README.md)] [[广度优先搜索](../breadth-first-search/README.md)] | Easy | -| 107 | [二叉树的层序遍历 II](../../problems/binary-tree-level-order-traversal-ii) | [[树](../tree/README.md)] [[广度优先搜索](../breadth-first-search/README.md)] | Easy | -| 103 | [二叉树的锯齿形层序遍历](../../problems/binary-tree-zigzag-level-order-traversal) | [[栈](../stack/README.md)] [[树](../tree/README.md)] [[广度优先搜索](../breadth-first-search/README.md)] | Medium | -| 102 | [二叉树的层序遍历](../../problems/binary-tree-level-order-traversal) | [[树](../tree/README.md)] [[广度优先搜索](../breadth-first-search/README.md)] | Medium | -| 101 | [对称二叉树](../../problems/symmetric-tree) | [[树](../tree/README.md)] [[深度优先搜索](../depth-first-search/README.md)] [[广度优先搜索](../breadth-first-search/README.md)] | Easy | diff --git a/tag/depth-first-search/README.md b/tag/depth-first-search/README.md index 61e398909..9deef5ef0 100644 --- a/tag/depth-first-search/README.md +++ b/tag/depth-first-search/README.md @@ -9,6 +9,8 @@ | # | 题目 | 标签 | 难度 | | :-: | - | - | :-: | +| 1740 | [Find Distance in a Binary Tree](../../problems/find-distance-in-a-binary-tree) 🔒 | [[树](../tree/README.md)] [[深度优先搜索](../depth-first-search/README.md)] [[广度优先搜索](../breadth-first-search/README.md)] | Easy | +| 1730 | [Shortest Path to Get Food](../../problems/shortest-path-to-get-food) | [[深度优先搜索](../depth-first-search/README.md)] [[广度优先搜索](../breadth-first-search/README.md)] [[图](../graph/README.md)] | Medium | | 1722 | [执行交换操作后的最小汉明距离](../../problems/minimize-hamming-distance-after-swap-operations) | [[贪心算法](../greedy/README.md)] [[深度优先搜索](../depth-first-search/README.md)] [[并查集](../union-find/README.md)] | Medium | | 1676 | [二叉树的最近公共祖先 IV](../../problems/lowest-common-ancestor-of-a-binary-tree-iv) 🔒 | [[树](../tree/README.md)] [[深度优先搜索](../depth-first-search/README.md)] | Medium | | 1666 | [改变二叉树的根节点](../../problems/change-the-root-of-a-binary-tree) 🔒 | [[树](../tree/README.md)] [[深度优先搜索](../depth-first-search/README.md)] | Medium | @@ -121,7 +123,7 @@ | 394 | [字符串解码](../../problems/decode-string) | [[栈](../stack/README.md)] [[深度优先搜索](../depth-first-search/README.md)] | Medium | | 366 | [寻找二叉树的叶子节点](../../problems/find-leaves-of-binary-tree) 🔒 | [[树](../tree/README.md)] [[深度优先搜索](../depth-first-search/README.md)] | Medium | | 364 | [加权嵌套序列和 II](../../problems/nested-list-weight-sum-ii) 🔒 | [[深度优先搜索](../depth-first-search/README.md)] | Medium | -| 339 | [嵌套列表权重和](../../problems/nested-list-weight-sum) 🔒 | [[深度优先搜索](../depth-first-search/README.md)] | Easy | +| 339 | [嵌套列表权重和](../../problems/nested-list-weight-sum) 🔒 | [[深度优先搜索](../depth-first-search/README.md)] [[广度优先搜索](../breadth-first-search/README.md)] | Easy | | 337 | [打家劫舍 III](../../problems/house-robber-iii) | [[树](../tree/README.md)] [[深度优先搜索](../depth-first-search/README.md)] | Medium | | 332 | [重新安排行程](../../problems/reconstruct-itinerary) | [[深度优先搜索](../depth-first-search/README.md)] [[图](../graph/README.md)] | Medium | | 329 | [矩阵中的最长递增路径](../../problems/longest-increasing-path-in-a-matrix) | [[深度优先搜索](../depth-first-search/README.md)] [[拓扑排序](../topological-sort/README.md)] [[记忆化](../memoization/README.md)] | Hard | @@ -130,6 +132,7 @@ | 301 | [删除无效的括号](../../problems/remove-invalid-parentheses) | [[深度优先搜索](../depth-first-search/README.md)] [[广度优先搜索](../breadth-first-search/README.md)] | Hard | | 261 | [以图判树](../../problems/graph-valid-tree) 🔒 | [[深度优先搜索](../depth-first-search/README.md)] [[广度优先搜索](../breadth-first-search/README.md)] [[并查集](../union-find/README.md)] [[图](../graph/README.md)] | Medium | | 257 | [二叉树的所有路径](../../problems/binary-tree-paths) | [[树](../tree/README.md)] [[深度优先搜索](../depth-first-search/README.md)] | Easy | +| 211 | [添加与搜索单词 - 数据结构设计](../../problems/design-add-and-search-words-data-structure) | [[深度优先搜索](../depth-first-search/README.md)] [[设计](../design/README.md)] [[字典树](../trie/README.md)] [[回溯算法](../backtracking/README.md)] | Medium | | 210 | [课程表 II](../../problems/course-schedule-ii) | [[深度优先搜索](../depth-first-search/README.md)] [[广度优先搜索](../breadth-first-search/README.md)] [[图](../graph/README.md)] [[拓扑排序](../topological-sort/README.md)] | Medium | | 207 | [课程表](../../problems/course-schedule) | [[深度优先搜索](../depth-first-search/README.md)] [[广度优先搜索](../breadth-first-search/README.md)] [[图](../graph/README.md)] [[拓扑排序](../topological-sort/README.md)] | Medium | | 200 | [岛屿数量](../../problems/number-of-islands) | [[深度优先搜索](../depth-first-search/README.md)] [[广度优先搜索](../breadth-first-search/README.md)] [[并查集](../union-find/README.md)] | Medium | diff --git a/tag/design/README.md b/tag/design/README.md index 4a85371d3..1bbe3ca62 100644 --- a/tag/design/README.md +++ b/tag/design/README.md @@ -62,7 +62,7 @@ | 244 | [最短单词距离 II](../../problems/shortest-word-distance-ii) 🔒 | [[设计](../design/README.md)] [[哈希表](../hash-table/README.md)] | Medium | | 232 | [用栈实现队列](../../problems/implement-queue-using-stacks) | [[栈](../stack/README.md)] [[设计](../design/README.md)] | Easy | | 225 | [用队列实现栈](../../problems/implement-stack-using-queues) | [[栈](../stack/README.md)] [[设计](../design/README.md)] | Easy | -| 211 | [添加与搜索单词 - 数据结构设计](../../problems/design-add-and-search-words-data-structure) | [[设计](../design/README.md)] [[字典树](../trie/README.md)] [[回溯算法](../backtracking/README.md)] | Medium | +| 211 | [添加与搜索单词 - 数据结构设计](../../problems/design-add-and-search-words-data-structure) | [[深度优先搜索](../depth-first-search/README.md)] [[设计](../design/README.md)] [[字典树](../trie/README.md)] [[回溯算法](../backtracking/README.md)] | Medium | | 208 | [实现 Trie (前缀树)](../../problems/implement-trie-prefix-tree) | [[设计](../design/README.md)] [[字典树](../trie/README.md)] | Medium | | 173 | [二叉搜索树迭代器](../../problems/binary-search-tree-iterator) | [[栈](../stack/README.md)] [[树](../tree/README.md)] [[设计](../design/README.md)] | Medium | | 170 | [两数之和 III - 数据结构设计](../../problems/two-sum-iii-data-structure-design) 🔒 | [[设计](../design/README.md)] [[哈希表](../hash-table/README.md)] | Easy | diff --git a/tag/dynamic-programming/README.md b/tag/dynamic-programming/README.md index cce163a3a..792ed5487 100644 --- a/tag/dynamic-programming/README.md +++ b/tag/dynamic-programming/README.md @@ -9,6 +9,8 @@ | # | 题目 | 标签 | 难度 | | :-: | - | - | :-: | +| 1728 | [猫和老鼠 II](../../problems/cat-and-mouse-ii) | [[动态规划](../dynamic-programming/README.md)] | Hard | +| 1724 | [Checking Existence of Edge Length Limited Paths II](../../problems/checking-existence-of-edge-length-limited-paths-ii) 🔒 | [[并查集](../union-find/README.md)] [[图](../graph/README.md)] [[动态规划](../dynamic-programming/README.md)] | Hard | | 1706 | [球会落何处](../../problems/where-will-the-ball-fall) | [[动态规划](../dynamic-programming/README.md)] | Medium | | 1692 | [计算分配糖果的不同方式](../../problems/count-ways-to-distribute-candies) 🔒 | [[动态规划](../dynamic-programming/README.md)] | Hard | | 1691 | [堆叠长方体的最大高度](../../problems/maximum-height-by-stacking-cuboids) | [[排序](../sort/README.md)] [[动态规划](../dynamic-programming/README.md)] | Hard | @@ -87,7 +89,7 @@ | 1227 | [飞机座位分配概率](../../problems/airplane-seat-assignment-probability) | [[脑筋急转弯](../brainteaser/README.md)] [[数学](../math/README.md)] [[动态规划](../dynamic-programming/README.md)] | Medium | | 1223 | [掷骰子模拟](../../problems/dice-roll-simulation) | [[动态规划](../dynamic-programming/README.md)] | Medium | | 1220 | [统计元音字母序列的数目](../../problems/count-vowels-permutation) | [[动态规划](../dynamic-programming/README.md)] | Hard | -| 1218 | [最长定差子序列](../../problems/longest-arithmetic-subsequence-of-given-difference) | [[数学](../math/README.md)] [[动态规划](../dynamic-programming/README.md)] | Medium | +| 1218 | [最长定差子序列](../../problems/longest-arithmetic-subsequence-of-given-difference) | [[哈希表](../hash-table/README.md)] [[数学](../math/README.md)] [[动态规划](../dynamic-programming/README.md)] | Medium | | 1216 | [验证回文字符串 III](../../problems/valid-palindrome-iii) 🔒 | [[字符串](../string/README.md)] [[动态规划](../dynamic-programming/README.md)] | Hard | | 1199 | [建造街区的最短时间](../../problems/minimum-time-to-build-blocks) 🔒 | [[数学](../math/README.md)] [[动态规划](../dynamic-programming/README.md)] | Hard | | 1191 | [K 次串联后最大子数组之和](../../problems/k-concatenation-maximum-sum) | [[动态规划](../dynamic-programming/README.md)] | Medium | @@ -221,7 +223,7 @@ | 256 | [粉刷房子](../../problems/paint-house) 🔒 | [[动态规划](../dynamic-programming/README.md)] | Medium | | 221 | [最大正方形](../../problems/maximal-square) | [[动态规划](../dynamic-programming/README.md)] | Medium | | 213 | [打家劫舍 II](../../problems/house-robber-ii) | [[动态规划](../dynamic-programming/README.md)] | Medium | -| 198 | [打家劫舍](../../problems/house-robber) | [[动态规划](../dynamic-programming/README.md)] | Easy | +| 198 | [打家劫舍](../../problems/house-robber) | [[动态规划](../dynamic-programming/README.md)] | Medium | | 188 | [买卖股票的最佳时机 IV](../../problems/best-time-to-buy-and-sell-stock-iv) | [[动态规划](../dynamic-programming/README.md)] | Hard | | 174 | [地下城游戏](../../problems/dungeon-game) | [[二分查找](../binary-search/README.md)] [[动态规划](../dynamic-programming/README.md)] | Hard | | 152 | [乘积最大子数组](../../problems/maximum-product-subarray) | [[数组](../array/README.md)] [[动态规划](../dynamic-programming/README.md)] | Medium | @@ -246,6 +248,7 @@ | 62 | [不同路径](../../problems/unique-paths) | [[数组](../array/README.md)] [[动态规划](../dynamic-programming/README.md)] | Medium | | 53 | [最大子序和](../../problems/maximum-subarray) | [[数组](../array/README.md)] [[分治算法](../divide-and-conquer/README.md)] [[动态规划](../dynamic-programming/README.md)] | Easy | | 44 | [通配符匹配](../../problems/wildcard-matching) | [[贪心算法](../greedy/README.md)] [[字符串](../string/README.md)] [[动态规划](../dynamic-programming/README.md)] [[回溯算法](../backtracking/README.md)] | Hard | +| 42 | [接雨水](../../problems/trapping-rain-water) | [[栈](../stack/README.md)] [[数组](../array/README.md)] [[双指针](../two-pointers/README.md)] [[动态规划](../dynamic-programming/README.md)] | Hard | | 32 | [最长有效括号](../../problems/longest-valid-parentheses) | [[字符串](../string/README.md)] [[动态规划](../dynamic-programming/README.md)] | Hard | | 10 | [正则表达式匹配](../../problems/regular-expression-matching) | [[字符串](../string/README.md)] [[动态规划](../dynamic-programming/README.md)] [[回溯算法](../backtracking/README.md)] | Hard | | 5 | [最长回文子串](../../problems/longest-palindromic-substring) | [[字符串](../string/README.md)] [[动态规划](../dynamic-programming/README.md)] | Medium | diff --git a/tag/graph/README.md b/tag/graph/README.md index ba9a7fc00..986d03a27 100644 --- a/tag/graph/README.md +++ b/tag/graph/README.md @@ -9,6 +9,8 @@ | # | 题目 | 标签 | 难度 | | :-: | - | - | :-: | +| 1730 | [Shortest Path to Get Food](../../problems/shortest-path-to-get-food) | [[深度优先搜索](../depth-first-search/README.md)] [[广度优先搜索](../breadth-first-search/README.md)] [[图](../graph/README.md)] | Medium | +| 1724 | [Checking Existence of Edge Length Limited Paths II](../../problems/checking-existence-of-edge-length-limited-paths-ii) 🔒 | [[并查集](../union-find/README.md)] [[图](../graph/README.md)] [[动态规划](../dynamic-programming/README.md)] | Hard | | 1719 | [重构一棵树的方案数](../../problems/number-of-ways-to-reconstruct-a-tree) | [[树](../tree/README.md)] [[图](../graph/README.md)] | Hard | | 1631 | [最小体力消耗路径](../../problems/path-with-minimum-effort) | [[深度优先搜索](../depth-first-search/README.md)] [[并查集](../union-find/README.md)] [[图](../graph/README.md)] [[二分查找](../binary-search/README.md)] | Medium | | 1615 | [最大网络秩](../../problems/maximal-network-rank) | [[图](../graph/README.md)] | Medium | diff --git a/tag/greedy/README.md b/tag/greedy/README.md index 87df25ab7..a9e90fd80 100644 --- a/tag/greedy/README.md +++ b/tag/greedy/README.md @@ -9,12 +9,17 @@ | # | 题目 | 标签 | 难度 | | :-: | - | - | :-: | +| 1737 | [满足三条件之一需改变的最少字符数](../../problems/change-minimum-characters-to-satisfy-one-of-three-conditions) | [[贪心算法](../greedy/README.md)] [[字符串](../string/README.md)] | Medium | +| 1736 | [替换隐藏数字得到的最晚时间](../../problems/latest-time-by-replacing-hidden-digits) | [[贪心算法](../greedy/README.md)] [[字符串](../string/README.md)] | Easy | +| 1733 | [需要教语言的最少人数](../../problems/minimum-number-of-people-to-teach) | [[贪心算法](../greedy/README.md)] [[数组](../array/README.md)] | Medium | +| 1727 | [重新排列后的最大子矩阵](../../problems/largest-submatrix-with-rearrangements) | [[贪心算法](../greedy/README.md)] [[排序](../sort/README.md)] | Medium | +| 1725 | [可以形成最大正方形的矩形数目](../../problems/number-of-rectangles-that-can-form-the-largest-square) | [[贪心算法](../greedy/README.md)] | Easy | | 1722 | [执行交换操作后的最小汉明距离](../../problems/minimize-hamming-distance-after-swap-operations) | [[贪心算法](../greedy/README.md)] [[深度优先搜索](../depth-first-search/README.md)] [[并查集](../union-find/README.md)] | Medium | | 1717 | [删除子字符串的最大得分](../../problems/maximum-score-from-removing-substrings) | [[贪心算法](../greedy/README.md)] | Medium | | 1716 | [计算力扣银行的钱](../../problems/calculate-money-in-leetcode-bank) | [[贪心算法](../greedy/README.md)] [[数学](../math/README.md)] | Easy | | 1713 | [得到子序列的最少操作次数](../../problems/minimum-operations-to-make-a-subsequence) | [[贪心算法](../greedy/README.md)] | Hard | | 1710 | [卡车上的最大单元数](../../problems/maximum-units-on-a-truck) | [[贪心算法](../greedy/README.md)] [[排序](../sort/README.md)] | Easy | -| 1708 | [Largest Subarray Length K](../../problems/largest-subarray-length-k) 🔒 | [[贪心算法](../greedy/README.md)] [[数组](../array/README.md)] | Easy | +| 1708 | [长度为 K 的最大子数组](../../problems/largest-subarray-length-k) 🔒 | [[贪心算法](../greedy/README.md)] [[数组](../array/README.md)] | Easy | | 1705 | [吃苹果的最大数目](../../problems/maximum-number-of-eaten-apples) | [[堆](../heap/README.md)] [[贪心算法](../greedy/README.md)] | Medium | | 1702 | [修改后的最大二进制字符串](../../problems/maximum-binary-string-after-change) | [[贪心算法](../greedy/README.md)] | Medium | | 1689 | [十-二进制数的最少数目](../../problems/partitioning-into-minimum-number-of-deci-binary-numbers) | [[贪心算法](../greedy/README.md)] | Medium | @@ -22,11 +27,11 @@ | 1685 | [有序数组中差绝对值之和](../../problems/sum-of-absolute-differences-in-a-sorted-array) | [[贪心算法](../greedy/README.md)] [[数学](../math/README.md)] | Medium | | 1681 | [最小不兼容性](../../problems/minimum-incompatibility) | [[贪心算法](../greedy/README.md)] [[回溯算法](../backtracking/README.md)] | Hard | | 1674 | [使数组互补的最少操作次数](../../problems/minimum-moves-to-make-array-complementary) | [[贪心算法](../greedy/README.md)] | Medium | -| 1673 | [找出最具竞争力的子序列](../../problems/find-the-most-competitive-subsequence) | [[栈](../stack/README.md)] [[贪心算法](../greedy/README.md)] | Medium | +| 1673 | [找出最具竞争力的子序列](../../problems/find-the-most-competitive-subsequence) | [[栈](../stack/README.md)] [[堆](../heap/README.md)] [[贪心算法](../greedy/README.md)] [[队列](../queue/README.md)] | Medium | | 1665 | [完成所有任务的最少初始能量](../../problems/minimum-initial-energy-to-finish-tasks) | [[贪心算法](../greedy/README.md)] | Hard | | 1664 | [生成平衡数组的方案数](../../problems/ways-to-make-a-fair-array) | [[贪心算法](../greedy/README.md)] [[动态规划](../dynamic-programming/README.md)] | Medium | | 1663 | [具有给定数值的最小字符串](../../problems/smallest-string-with-a-given-numeric-value) | [[贪心算法](../greedy/README.md)] | Medium | -| 1658 | [将 x 减到 0 的最小操作数](../../problems/minimum-operations-to-reduce-x-to-zero) | [[贪心算法](../greedy/README.md)] [[双指针](../two-pointers/README.md)] [[二分查找](../binary-search/README.md)] | Medium | +| 1658 | [将 x 减到 0 的最小操作数](../../problems/minimum-operations-to-reduce-x-to-zero) | [[贪心算法](../greedy/README.md)] [[双指针](../two-pointers/README.md)] [[二分查找](../binary-search/README.md)] [[Sliding Window](../sliding-window/README.md)] | Medium | | 1657 | [确定两个字符串是否接近](../../problems/determine-if-two-strings-are-close) | [[贪心算法](../greedy/README.md)] | Medium | | 1653 | [使字符串平衡的最少删除次数](../../problems/minimum-deletions-to-make-string-balanced) | [[贪心算法](../greedy/README.md)] [[字符串](../string/README.md)] | Medium | | 1648 | [销售价值减少的颜色球](../../problems/sell-diminishing-valued-colored-balls) | [[贪心算法](../greedy/README.md)] [[排序](../sort/README.md)] [[数学](../math/README.md)] | Medium | diff --git a/tag/hash-table/README.md b/tag/hash-table/README.md index 00cd2fdf4..79ef05332 100644 --- a/tag/hash-table/README.md +++ b/tag/hash-table/README.md @@ -9,6 +9,7 @@ | # | 题目 | 标签 | 难度 | | :-: | - | - | :-: | +| 1726 | [同积元组](../../problems/tuple-with-same-product) | [[数组](../array/README.md)] [[哈希表](../hash-table/README.md)] | Medium | | 1711 | [大餐计数](../../problems/count-good-meals) | [[数组](../array/README.md)] [[哈希表](../hash-table/README.md)] [[双指针](../two-pointers/README.md)] | Medium | | 1679 | [K 和数对的最大数目](../../problems/max-number-of-k-sum-pairs) | [[哈希表](../hash-table/README.md)] | Medium | | 1640 | [能否连接形成数组](../../problems/check-array-formation-through-concatenation) | [[排序](../sort/README.md)] [[数组](../array/README.md)] [[哈希表](../hash-table/README.md)] | Easy | @@ -29,6 +30,7 @@ | 1261 | [在受污染的二叉树中查找元素](../../problems/find-elements-in-a-contaminated-binary-tree) | [[树](../tree/README.md)] [[哈希表](../hash-table/README.md)] | Medium | | 1244 | [力扣排行榜](../../problems/design-a-leaderboard) 🔒 | [[排序](../sort/README.md)] [[设计](../design/README.md)] [[哈希表](../hash-table/README.md)] | Medium | | 1224 | [最大相等频率](../../problems/maximum-equal-frequency) | [[哈希表](../hash-table/README.md)] | Hard | +| 1218 | [最长定差子序列](../../problems/longest-arithmetic-subsequence-of-given-difference) | [[哈希表](../hash-table/README.md)] [[数学](../math/README.md)] [[动态规划](../dynamic-programming/README.md)] | Medium | | 1213 | [三个有序数组的交集](../../problems/intersection-of-three-sorted-arrays) 🔒 | [[哈希表](../hash-table/README.md)] [[双指针](../two-pointers/README.md)] | Easy | | 1207 | [独一无二的出现次数](../../problems/unique-number-of-occurrences) | [[哈希表](../hash-table/README.md)] | Easy | | 1198 | [找出所有行中最小公共元素](../../problems/find-smallest-common-element-in-all-rows) 🔒 | [[哈希表](../hash-table/README.md)] [[二分查找](../binary-search/README.md)] | Medium | diff --git a/tag/heap/README.md b/tag/heap/README.md index 885e5e859..4bf8bcc92 100644 --- a/tag/heap/README.md +++ b/tag/heap/README.md @@ -11,12 +11,13 @@ | :-: | - | - | :-: | | 1705 | [吃苹果的最大数目](../../problems/maximum-number-of-eaten-apples) | [[堆](../heap/README.md)] [[贪心算法](../greedy/README.md)] | Medium | | 1675 | [数组的最小偏移量](../../problems/minimize-deviation-in-array) | [[堆](../heap/README.md)] [[Ordered Map](../ordered-map/README.md)] | Hard | +| 1673 | [找出最具竞争力的子序列](../../problems/find-the-most-competitive-subsequence) | [[栈](../stack/README.md)] [[堆](../heap/README.md)] [[贪心算法](../greedy/README.md)] [[队列](../queue/README.md)] | Medium | | 1642 | [可以到达的最远建筑](../../problems/furthest-building-you-can-reach) | [[堆](../heap/README.md)] [[二分查找](../binary-search/README.md)] | Medium | | 1439 | [有序矩阵中的第 k 个最小数组和](../../problems/find-the-kth-smallest-sum-of-a-matrix-with-sorted-rows) | [[堆](../heap/README.md)] | Hard | | 1054 | [距离相等的条形码](../../problems/distant-barcodes) | [[堆](../heap/README.md)] [[排序](../sort/README.md)] | Medium | | 1046 | [最后一块石头的重量](../../problems/last-stone-weight) | [[堆](../heap/README.md)] [[贪心算法](../greedy/README.md)] | Easy | | 973 | [最接近原点的 K 个点](../../problems/k-closest-points-to-origin) | [[堆](../heap/README.md)] [[排序](../sort/README.md)] [[分治算法](../divide-and-conquer/README.md)] | Medium | -| 882 | [细分图中的可到达结点](../../problems/reachable-nodes-in-subdivided-graph) | [[堆](../heap/README.md)] | Hard | +| 882 | [细分图中的可到达结点](../../problems/reachable-nodes-in-subdivided-graph) | [[堆](../heap/README.md)] [[广度优先搜索](../breadth-first-search/README.md)] | Hard | | 871 | [最低加油次数](../../problems/minimum-number-of-refueling-stops) | [[堆](../heap/README.md)] [[动态规划](../dynamic-programming/README.md)] | Hard | | 864 | [获取所有钥匙的最短路径](../../problems/shortest-path-to-get-all-keys) | [[堆](../heap/README.md)] [[广度优先搜索](../breadth-first-search/README.md)] | Hard | | 857 | [雇佣 K 名工人的最低成本](../../problems/minimum-cost-to-hire-k-workers) | [[堆](../heap/README.md)] | Hard | diff --git a/tag/line-sweep/README.md b/tag/line-sweep/README.md index 592ea3e0f..932db1472 100644 --- a/tag/line-sweep/README.md +++ b/tag/line-sweep/README.md @@ -9,3 +9,9 @@ | # | 题目 | 标签 | 难度 | | :-: | - | - | :-: | +| 1288 | [删除被覆盖区间](../../problems/remove-covered-intervals) | [[贪心算法](../greedy/README.md)] [[排序](../sort/README.md)] [[Line Sweep](../line-sweep/README.md)] | Medium | +| 1272 | [删除区间](../../problems/remove-interval) 🔒 | [[数学](../math/README.md)] [[Line Sweep](../line-sweep/README.md)] | Medium | +| 1229 | [安排会议日程](../../problems/meeting-scheduler) 🔒 | [[排序](../sort/README.md)] [[双指针](../two-pointers/README.md)] [[Line Sweep](../line-sweep/README.md)] | Medium | +| 850 | [矩形面积 II](../../problems/rectangle-area-ii) | [[线段树](../segment-tree/README.md)] [[Line Sweep](../line-sweep/README.md)] | Hard | +| 391 | [完美矩形](../../problems/perfect-rectangle) | [[Line Sweep](../line-sweep/README.md)] | Hard | +| 218 | [天际线问题](../../problems/the-skyline-problem) | [[堆](../heap/README.md)] [[树状数组](../binary-indexed-tree/README.md)] [[线段树](../segment-tree/README.md)] [[分治算法](../divide-and-conquer/README.md)] [[Line Sweep](../line-sweep/README.md)] | Hard | diff --git a/tag/linked-list/README.md b/tag/linked-list/README.md index a34ab29f8..8103f6eff 100644 --- a/tag/linked-list/README.md +++ b/tag/linked-list/README.md @@ -50,5 +50,5 @@ | 24 | [两两交换链表中的节点](../../problems/swap-nodes-in-pairs) | [[递归](../recursion/README.md)] [[链表](../linked-list/README.md)] | Medium | | 23 | [合并K个升序链表](../../problems/merge-k-sorted-lists) | [[堆](../heap/README.md)] [[链表](../linked-list/README.md)] [[分治算法](../divide-and-conquer/README.md)] | Hard | | 21 | [合并两个有序链表](../../problems/merge-two-sorted-lists) | [[递归](../recursion/README.md)] [[链表](../linked-list/README.md)] | Easy | -| 19 | [删除链表的倒数第N个节点](../../problems/remove-nth-node-from-end-of-list) | [[链表](../linked-list/README.md)] [[双指针](../two-pointers/README.md)] | Medium | +| 19 | [删除链表的倒数第 N 个结点](../../problems/remove-nth-node-from-end-of-list) | [[链表](../linked-list/README.md)] [[双指针](../two-pointers/README.md)] | Medium | | 2 | [两数相加](../../problems/add-two-numbers) | [[递归](../recursion/README.md)] [[链表](../linked-list/README.md)] [[数学](../math/README.md)] | Medium | diff --git a/tag/math/README.md b/tag/math/README.md index c58dcdb99..841dc593e 100644 --- a/tag/math/README.md +++ b/tag/math/README.md @@ -9,6 +9,8 @@ | # | 题目 | 标签 | 难度 | | :-: | - | - | :-: | +| 1739 | [放置盒子](../../problems/building-boxes) | [[数学](../math/README.md)] [[二分查找](../binary-search/README.md)] | Hard | +| 1735 | [生成乘积数组的方案数](../../problems/count-ways-to-make-array-with-product) | [[数学](../math/README.md)] | Hard | | 1716 | [计算力扣银行的钱](../../problems/calculate-money-in-leetcode-bank) | [[贪心算法](../greedy/README.md)] [[数学](../math/README.md)] | Easy | | 1685 | [有序数组中差绝对值之和](../../problems/sum-of-absolute-differences-in-a-sorted-array) | [[贪心算法](../greedy/README.md)] [[数学](../math/README.md)] | Medium | | 1680 | [连接连续二进制数字](../../problems/concatenation-of-consecutive-binary-numbers) | [[数学](../math/README.md)] | Medium | @@ -48,12 +50,12 @@ | 1253 | [重构 2 行二进制矩阵](../../problems/reconstruct-a-2-row-binary-matrix) | [[贪心算法](../greedy/README.md)] [[数学](../math/README.md)] | Medium | | 1250 | [检查「好数组」](../../problems/check-if-it-is-a-good-array) | [[数学](../math/README.md)] | Hard | | 1238 | [循环码排列](../../problems/circular-permutation-in-binary-representation) | [[数学](../math/README.md)] | Medium | -| 1237 | [找出给定方程的正整数解](../../problems/find-positive-integer-solution-for-a-given-equation) | [[数学](../math/README.md)] [[二分查找](../binary-search/README.md)] | Easy | +| 1237 | [找出给定方程的正整数解](../../problems/find-positive-integer-solution-for-a-given-equation) | [[数学](../math/README.md)] [[二分查找](../binary-search/README.md)] | Medium | | 1232 | [缀点成线](../../problems/check-if-it-is-a-straight-line) | [[几何](../geometry/README.md)] [[数组](../array/README.md)] [[数学](../math/README.md)] | Easy | | 1230 | [抛掷硬币](../../problems/toss-strange-coins) 🔒 | [[数学](../math/README.md)] [[动态规划](../dynamic-programming/README.md)] | Medium | | 1228 | [等差数列中缺失的数字](../../problems/missing-number-in-arithmetic-progression) 🔒 | [[数学](../math/README.md)] | Easy | | 1227 | [飞机座位分配概率](../../problems/airplane-seat-assignment-probability) | [[脑筋急转弯](../brainteaser/README.md)] [[数学](../math/README.md)] [[动态规划](../dynamic-programming/README.md)] | Medium | -| 1218 | [最长定差子序列](../../problems/longest-arithmetic-subsequence-of-given-difference) | [[数学](../math/README.md)] [[动态规划](../dynamic-programming/README.md)] | Medium | +| 1218 | [最长定差子序列](../../problems/longest-arithmetic-subsequence-of-given-difference) | [[哈希表](../hash-table/README.md)] [[数学](../math/README.md)] [[动态规划](../dynamic-programming/README.md)] | Medium | | 1217 | [玩筹码](../../problems/minimum-cost-to-move-chips-to-the-same-position) | [[贪心算法](../greedy/README.md)] [[数组](../array/README.md)] [[数学](../math/README.md)] | Easy | | 1201 | [丑数 III](../../problems/ugly-number-iii) | [[数学](../math/README.md)] [[二分查找](../binary-search/README.md)] | Medium | | 1199 | [建造街区的最短时间](../../problems/minimum-time-to-build-blocks) 🔒 | [[数学](../math/README.md)] [[动态规划](../dynamic-programming/README.md)] | Hard | diff --git a/tag/memoization/README.md b/tag/memoization/README.md index f418d566c..2c6a5dffd 100644 --- a/tag/memoization/README.md +++ b/tag/memoization/README.md @@ -9,3 +9,4 @@ | # | 题目 | 标签 | 难度 | | :-: | - | - | :-: | +| 329 | [矩阵中的最长递增路径](../../problems/longest-increasing-path-in-a-matrix) | [[深度优先搜索](../depth-first-search/README.md)] [[拓扑排序](../topological-sort/README.md)] [[记忆化](../memoization/README.md)] | Hard | diff --git a/tag/ordered-map/README.md b/tag/ordered-map/README.md index 85faedb8e..52afd5989 100644 --- a/tag/ordered-map/README.md +++ b/tag/ordered-map/README.md @@ -9,17 +9,3 @@ | # | 题目 | 标签 | 难度 | | :-: | - | - | :-: | -| 1675 | [数组的最小偏移量](../../problems/minimize-deviation-in-array) | [[堆](../heap/README.md)] [[Ordered Map](../ordered-map/README.md)] | Hard | -| 1649 | [通过指令创建有序数组](../../problems/create-sorted-array-through-instructions) | [[树状数组](../binary-indexed-tree/README.md)] [[线段树](../segment-tree/README.md)] [[二分查找](../binary-search/README.md)] [[Ordered Map](../ordered-map/README.md)] | Hard | -| 1606 | [找到处理最多请求的服务器](../../problems/find-servers-that-handled-most-number-of-requests) | [[Ordered Map](../ordered-map/README.md)] | Hard | -| 1604 | [警告一小时内使用相同员工卡大于等于三次的人](../../problems/alert-using-same-key-card-three-or-more-times-in-a-one-hour-period) | [[字符串](../string/README.md)] [[Ordered Map](../ordered-map/README.md)] | Medium | -| 975 | [奇偶跳](../../problems/odd-even-jump) | [[栈](../stack/README.md)] [[动态规划](../dynamic-programming/README.md)] [[Ordered Map](../ordered-map/README.md)] | Hard | -| 855 | [考场就座](../../problems/exam-room) | [[Ordered Map](../ordered-map/README.md)] | Medium | -| 846 | [一手顺子](../../problems/hand-of-straights) | [[Ordered Map](../ordered-map/README.md)] | Medium | -| 732 | [我的日程安排表 III](../../problems/my-calendar-iii) | [[线段树](../segment-tree/README.md)] [[Ordered Map](../ordered-map/README.md)] | Hard | -| 731 | [我的日程安排表 II](../../problems/my-calendar-ii) | [[Ordered Map](../ordered-map/README.md)] | Medium | -| 715 | [Range 模块](../../problems/range-module) | [[线段树](../segment-tree/README.md)] [[Ordered Map](../ordered-map/README.md)] | Hard | -| 699 | [掉落的方块](../../problems/falling-squares) | [[线段树](../segment-tree/README.md)] [[Ordered Map](../ordered-map/README.md)] | Hard | -| 683 | [K 个关闭的灯泡](../../problems/k-empty-slots) 🔒 | [[Ordered Map](../ordered-map/README.md)] | Hard | -| 352 | [将数据流变为多个不相交区间](../../problems/data-stream-as-disjoint-intervals) | [[二分查找](../binary-search/README.md)] [[Ordered Map](../ordered-map/README.md)] | Hard | -| 220 | [存在重复元素 III](../../problems/contains-duplicate-iii) | [[排序](../sort/README.md)] [[Ordered Map](../ordered-map/README.md)] | Medium | diff --git a/tag/queue/README.md b/tag/queue/README.md index 16db88027..8922feba8 100644 --- a/tag/queue/README.md +++ b/tag/queue/README.md @@ -9,12 +9,3 @@ | # | 题目 | 标签 | 难度 | | :-: | - | - | :-: | -| 933 | [最近的请求次数](../../problems/number-of-recent-calls) | [[队列](../queue/README.md)] | Easy | -| 862 | [和至少为 K 的最短子数组](../../problems/shortest-subarray-with-sum-at-least-k) | [[队列](../queue/README.md)] [[二分查找](../binary-search/README.md)] | Hard | -| 641 | [设计循环双端队列](../../problems/design-circular-deque) | [[设计](../design/README.md)] [[队列](../queue/README.md)] | Medium | -| 622 | [设计循环队列](../../problems/design-circular-queue) | [[设计](../design/README.md)] [[队列](../queue/README.md)] | Medium | -| 621 | [任务调度器](../../problems/task-scheduler) | [[贪心算法](../greedy/README.md)] [[队列](../queue/README.md)] [[数组](../array/README.md)] | Medium | -| 582 | [杀死进程](../../problems/kill-process) 🔒 | [[树](../tree/README.md)] [[队列](../queue/README.md)] | Medium | -| 363 | [矩形区域不超过 K 的最大数值和](../../problems/max-sum-of-rectangle-no-larger-than-k) | [[队列](../queue/README.md)] [[二分查找](../binary-search/README.md)] [[动态规划](../dynamic-programming/README.md)] | Hard | -| 353 | [贪吃蛇](../../problems/design-snake-game) 🔒 | [[设计](../design/README.md)] [[队列](../queue/README.md)] | Medium | -| 346 | [数据流中的移动平均值](../../problems/moving-average-from-data-stream) 🔒 | [[设计](../design/README.md)] [[队列](../queue/README.md)] | Easy | diff --git a/tag/recursion/README.md b/tag/recursion/README.md index 614bd16a1..f17ca04aa 100644 --- a/tag/recursion/README.md +++ b/tag/recursion/README.md @@ -27,6 +27,7 @@ | 726 | [原子的数量](../../problems/number-of-atoms) | [[栈](../stack/README.md)] [[递归](../recursion/README.md)] [[哈希表](../hash-table/README.md)] | Hard | | 698 | [划分为k个相等的子集](../../problems/partition-to-k-equal-sum-subsets) | [[递归](../recursion/README.md)] [[动态规划](../dynamic-programming/README.md)] | Medium | | 687 | [最长同值路径](../../problems/longest-univalue-path) | [[树](../tree/README.md)] [[递归](../recursion/README.md)] | Medium | +| 669 | [修剪二叉搜索树](../../problems/trim-a-binary-search-tree) | [[树](../tree/README.md)] [[递归](../recursion/README.md)] | Medium | | 625 | [最小因式分解](../../problems/minimum-factorization) 🔒 | [[递归](../recursion/README.md)] [[数学](../math/README.md)] | Medium | | 563 | [二叉树的坡度](../../problems/binary-tree-tilt) | [[树](../tree/README.md)] [[深度优先搜索](../depth-first-search/README.md)] [[递归](../recursion/README.md)] | Easy | | 544 | [输出比赛匹配对](../../problems/output-contest-matches) 🔒 | [[递归](../recursion/README.md)] [[字符串](../string/README.md)] | Medium | diff --git a/tag/rejection-sampling/README.md b/tag/rejection-sampling/README.md index 8622c93e1..fc2d396f2 100644 --- a/tag/rejection-sampling/README.md +++ b/tag/rejection-sampling/README.md @@ -9,3 +9,5 @@ | # | 题目 | 标签 | 难度 | | :-: | - | - | :-: | +| 478 | [在圆内随机生成点](../../problems/generate-random-point-in-a-circle) | [[数学](../math/README.md)] [[Random](../random/README.md)] [[Rejection Sampling](../rejection-sampling/README.md)] | Medium | +| 470 | [用 Rand7() 实现 Rand10()](../../problems/implement-rand10-using-rand7) | [[Random](../random/README.md)] [[Rejection Sampling](../rejection-sampling/README.md)] | Medium | diff --git a/tag/reservoir-sampling/README.md b/tag/reservoir-sampling/README.md index 7d9ca74cc..1fc516eb3 100644 --- a/tag/reservoir-sampling/README.md +++ b/tag/reservoir-sampling/README.md @@ -9,3 +9,5 @@ | # | 题目 | 标签 | 难度 | | :-: | - | - | :-: | +| 398 | [随机数索引](../../problems/random-pick-index) | [[蓄水池抽样](../reservoir-sampling/README.md)] | Medium | +| 382 | [链表随机节点](../../problems/linked-list-random-node) | [[蓄水池抽样](../reservoir-sampling/README.md)] | Medium | diff --git a/tag/segment-tree/README.md b/tag/segment-tree/README.md index b34d04e3d..bdf264168 100644 --- a/tag/segment-tree/README.md +++ b/tag/segment-tree/README.md @@ -9,19 +9,3 @@ | # | 题目 | 标签 | 难度 | | :-: | - | - | :-: | -| 1687 | [从仓库到码头运输箱子](../../problems/delivering-boxes-from-storage-to-ports) | [[线段树](../segment-tree/README.md)] [[双指针](../two-pointers/README.md)] [[动态规划](../dynamic-programming/README.md)] | Hard | -| 1649 | [通过指令创建有序数组](../../problems/create-sorted-array-through-instructions) | [[树状数组](../binary-indexed-tree/README.md)] [[线段树](../segment-tree/README.md)] [[二分查找](../binary-search/README.md)] [[Ordered Map](../ordered-map/README.md)] | Hard | -| 1526 | [形成目标数组的子数组最少增加次数](../../problems/minimum-number-of-increments-on-subarrays-to-form-a-target-array) | [[线段树](../segment-tree/README.md)] | Hard | -| 1521 | [找到最接近目标值的函数值](../../problems/find-a-value-of-a-mysterious-function-closest-to-target) | [[位运算](../bit-manipulation/README.md)] [[线段树](../segment-tree/README.md)] [[二分查找](../binary-search/README.md)] | Hard | -| 1353 | [最多可以参加的会议数目](../../problems/maximum-number-of-events-that-can-be-attended) | [[贪心算法](../greedy/README.md)] [[排序](../sort/README.md)] [[线段树](../segment-tree/README.md)] | Medium | -| 1157 | [子数组中占绝大多数的元素](../../problems/online-majority-element-in-subarray) | [[线段树](../segment-tree/README.md)] [[数组](../array/README.md)] [[二分查找](../binary-search/README.md)] | Hard | -| 850 | [矩形面积 II](../../problems/rectangle-area-ii) | [[线段树](../segment-tree/README.md)] [[Line Sweep](../line-sweep/README.md)] | Hard | -| 732 | [我的日程安排表 III](../../problems/my-calendar-iii) | [[线段树](../segment-tree/README.md)] [[Ordered Map](../ordered-map/README.md)] | Hard | -| 715 | [Range 模块](../../problems/range-module) | [[线段树](../segment-tree/README.md)] [[Ordered Map](../ordered-map/README.md)] | Hard | -| 699 | [掉落的方块](../../problems/falling-squares) | [[线段树](../segment-tree/README.md)] [[Ordered Map](../ordered-map/README.md)] | Hard | -| 493 | [翻转对](../../problems/reverse-pairs) | [[排序](../sort/README.md)] [[树状数组](../binary-indexed-tree/README.md)] [[线段树](../segment-tree/README.md)] [[二分查找](../binary-search/README.md)] [[分治算法](../divide-and-conquer/README.md)] | Hard | -| 327 | [区间和的个数](../../problems/count-of-range-sum) | [[排序](../sort/README.md)] [[树状数组](../binary-indexed-tree/README.md)] [[线段树](../segment-tree/README.md)] [[二分查找](../binary-search/README.md)] [[分治算法](../divide-and-conquer/README.md)] | Hard | -| 315 | [计算右侧小于当前元素的个数](../../problems/count-of-smaller-numbers-after-self) | [[排序](../sort/README.md)] [[树状数组](../binary-indexed-tree/README.md)] [[线段树](../segment-tree/README.md)] [[二分查找](../binary-search/README.md)] [[分治算法](../divide-and-conquer/README.md)] | Hard | -| 308 | [二维区域和检索 - 可变](../../problems/range-sum-query-2d-mutable) 🔒 | [[树状数组](../binary-indexed-tree/README.md)] [[线段树](../segment-tree/README.md)] | Hard | -| 307 | [区域和检索 - 数组可修改](../../problems/range-sum-query-mutable) | [[树状数组](../binary-indexed-tree/README.md)] [[线段树](../segment-tree/README.md)] | Medium | -| 218 | [天际线问题](../../problems/the-skyline-problem) | [[堆](../heap/README.md)] [[树状数组](../binary-indexed-tree/README.md)] [[线段树](../segment-tree/README.md)] [[分治算法](../divide-and-conquer/README.md)] [[Line Sweep](../line-sweep/README.md)] | Hard | diff --git a/tag/sliding-window/README.md b/tag/sliding-window/README.md index 101291dc2..56d607bc2 100644 --- a/tag/sliding-window/README.md +++ b/tag/sliding-window/README.md @@ -9,6 +9,7 @@ | # | 题目 | 标签 | 难度 | | :-: | - | - | :-: | +| 1658 | [将 x 减到 0 的最小操作数](../../problems/minimum-operations-to-reduce-x-to-zero) | [[贪心算法](../greedy/README.md)] [[双指针](../two-pointers/README.md)] [[二分查找](../binary-search/README.md)] [[Sliding Window](../sliding-window/README.md)] | Medium | | 1499 | [满足不等式的最大值](../../problems/max-value-of-equation) | [[数组](../array/README.md)] [[Sliding Window](../sliding-window/README.md)] | Hard | | 1498 | [满足条件的子序列数目](../../problems/number-of-subsequences-that-satisfy-the-given-sum-condition) | [[排序](../sort/README.md)] [[Sliding Window](../sliding-window/README.md)] | Medium | | 1456 | [定长子串中元音的最大数目](../../problems/maximum-number-of-vowels-in-a-substring-of-given-length) | [[字符串](../string/README.md)] [[Sliding Window](../sliding-window/README.md)] | Medium | diff --git a/tag/sort/README.md b/tag/sort/README.md index b691d2565..3ae174849 100644 --- a/tag/sort/README.md +++ b/tag/sort/README.md @@ -9,6 +9,7 @@ | # | 题目 | 标签 | 难度 | | :-: | - | - | :-: | +| 1727 | [重新排列后的最大子矩阵](../../problems/largest-submatrix-with-rearrangements) | [[贪心算法](../greedy/README.md)] [[排序](../sort/README.md)] | Medium | | 1710 | [卡车上的最大单元数](../../problems/maximum-units-on-a-truck) | [[贪心算法](../greedy/README.md)] [[排序](../sort/README.md)] | Easy | | 1697 | [检查边长度限制的路径是否存在](../../problems/checking-existence-of-edge-length-limited-paths) | [[排序](../sort/README.md)] [[并查集](../union-find/README.md)] | Hard | | 1691 | [堆叠长方体的最大高度](../../problems/maximum-height-by-stacking-cuboids) | [[排序](../sort/README.md)] [[动态规划](../dynamic-programming/README.md)] | Hard | @@ -43,6 +44,7 @@ | 1288 | [删除被覆盖区间](../../problems/remove-covered-intervals) | [[贪心算法](../greedy/README.md)] [[排序](../sort/README.md)] [[Line Sweep](../line-sweep/README.md)] | Medium | | 1244 | [力扣排行榜](../../problems/design-a-leaderboard) 🔒 | [[排序](../sort/README.md)] [[设计](../design/README.md)] [[哈希表](../hash-table/README.md)] | Medium | | 1235 | [规划兼职工作](../../problems/maximum-profit-in-job-scheduling) | [[排序](../sort/README.md)] [[二分查找](../binary-search/README.md)] [[动态规划](../dynamic-programming/README.md)] | Hard | +| 1229 | [安排会议日程](../../problems/meeting-scheduler) 🔒 | [[排序](../sort/README.md)] [[双指针](../two-pointers/README.md)] [[Line Sweep](../line-sweep/README.md)] | Medium | | 1183 | [矩阵中 1 的最大数量](../../problems/maximum-number-of-ones) 🔒 | [[排序](../sort/README.md)] [[数学](../math/README.md)] | Hard | | 1152 | [用户网站访问行为分析](../../problems/analyze-user-website-visit-pattern) 🔒 | [[排序](../sort/README.md)] [[数组](../array/README.md)] [[哈希表](../hash-table/README.md)] | Medium | | 1122 | [数组的相对排序](../../problems/relative-sort-array) | [[排序](../sort/README.md)] [[数组](../array/README.md)] | Easy | @@ -80,5 +82,5 @@ | 148 | [排序链表](../../problems/sort-list) | [[排序](../sort/README.md)] [[链表](../linked-list/README.md)] | Medium | | 147 | [对链表进行插入排序](../../problems/insertion-sort-list) | [[排序](../sort/README.md)] [[链表](../linked-list/README.md)] | Medium | | 75 | [颜色分类](../../problems/sort-colors) | [[排序](../sort/README.md)] [[数组](../array/README.md)] [[双指针](../two-pointers/README.md)] | Medium | -| 57 | [插入区间](../../problems/insert-interval) | [[排序](../sort/README.md)] [[数组](../array/README.md)] | Hard | +| 57 | [插入区间](../../problems/insert-interval) | [[排序](../sort/README.md)] [[数组](../array/README.md)] | Medium | | 56 | [合并区间](../../problems/merge-intervals) | [[排序](../sort/README.md)] [[数组](../array/README.md)] | Medium | diff --git a/tag/stack/README.md b/tag/stack/README.md index 9aabcd33e..238b0b4da 100644 --- a/tag/stack/README.md +++ b/tag/stack/README.md @@ -10,7 +10,7 @@ | # | 题目 | 标签 | 难度 | | :-: | - | - | :-: | | 1703 | [得到连续 K 个 1 的最少相邻交换次数](../../problems/minimum-adjacent-swaps-for-k-consecutive-ones) | [[栈](../stack/README.md)] | Hard | -| 1673 | [找出最具竞争力的子序列](../../problems/find-the-most-competitive-subsequence) | [[栈](../stack/README.md)] [[贪心算法](../greedy/README.md)] | Medium | +| 1673 | [找出最具竞争力的子序列](../../problems/find-the-most-competitive-subsequence) | [[栈](../stack/README.md)] [[堆](../heap/README.md)] [[贪心算法](../greedy/README.md)] [[队列](../queue/README.md)] | Medium | | 1598 | [文件夹操作日志搜集器](../../problems/crawler-log-folder) | [[栈](../stack/README.md)] | Easy | | 1544 | [整理字符串](../../problems/make-the-string-great) | [[栈](../stack/README.md)] [[字符串](../string/README.md)] | Easy | | 1541 | [平衡括号字符串的最少插入次数](../../problems/minimum-insertions-to-balance-a-parentheses-string) | [[栈](../stack/README.md)] [[字符串](../string/README.md)] | Medium | @@ -71,5 +71,5 @@ | 85 | [最大矩形](../../problems/maximal-rectangle) | [[栈](../stack/README.md)] [[数组](../array/README.md)] [[哈希表](../hash-table/README.md)] [[动态规划](../dynamic-programming/README.md)] | Hard | | 84 | [柱状图中最大的矩形](../../problems/largest-rectangle-in-histogram) | [[栈](../stack/README.md)] [[数组](../array/README.md)] | Hard | | 71 | [简化路径](../../problems/simplify-path) | [[栈](../stack/README.md)] [[字符串](../string/README.md)] | Medium | -| 42 | [接雨水](../../problems/trapping-rain-water) | [[栈](../stack/README.md)] [[数组](../array/README.md)] [[双指针](../two-pointers/README.md)] | Hard | +| 42 | [接雨水](../../problems/trapping-rain-water) | [[栈](../stack/README.md)] [[数组](../array/README.md)] [[双指针](../two-pointers/README.md)] [[动态规划](../dynamic-programming/README.md)] | Hard | | 20 | [有效的括号](../../problems/valid-parentheses) | [[栈](../stack/README.md)] [[字符串](../string/README.md)] | Easy | diff --git a/tag/string/README.md b/tag/string/README.md index 80ca3dd45..cd7990fb5 100644 --- a/tag/string/README.md +++ b/tag/string/README.md @@ -9,6 +9,8 @@ | # | 题目 | 标签 | 难度 | | :-: | - | - | :-: | +| 1737 | [满足三条件之一需改变的最少字符数](../../problems/change-minimum-characters-to-satisfy-one-of-three-conditions) | [[贪心算法](../greedy/README.md)] [[字符串](../string/README.md)] | Medium | +| 1736 | [替换隐藏数字得到的最晚时间](../../problems/latest-time-by-replacing-hidden-digits) | [[贪心算法](../greedy/README.md)] [[字符串](../string/README.md)] | Easy | | 1704 | [判断字符串的两半是否相似](../../problems/determine-if-string-halves-are-alike) | [[字符串](../string/README.md)] | Easy | | 1698 | [字符串的不同子字符串个数](../../problems/number-of-distinct-substrings-in-a-string) 🔒 | [[字典树](../trie/README.md)] [[字符串](../string/README.md)] | Medium | | 1694 | [重新格式化电话号码](../../problems/reformat-phone-number) | [[字符串](../string/README.md)] | Easy | @@ -83,7 +85,7 @@ | 1181 | [前后拼接](../../problems/before-and-after-puzzle) 🔒 | [[字符串](../string/README.md)] | Medium | | 1180 | [统计只含单一字母的子串](../../problems/count-substrings-with-only-one-distinct-letter) 🔒 | [[数学](../math/README.md)] [[字符串](../string/README.md)] | Easy | | 1177 | [构建回文串检测](../../problems/can-make-palindrome-from-substring) | [[数组](../array/README.md)] [[字符串](../string/README.md)] | Medium | -| 1170 | [比较字符串最小字母出现频次](../../problems/compare-strings-by-frequency-of-the-smallest-character) | [[数组](../array/README.md)] [[字符串](../string/README.md)] | Easy | +| 1170 | [比较字符串最小字母出现频次](../../problems/compare-strings-by-frequency-of-the-smallest-character) | [[数组](../array/README.md)] [[字符串](../string/README.md)] [[二分查找](../binary-search/README.md)] | Medium | | 1169 | [查询无效交易](../../problems/invalid-transactions) | [[数组](../array/README.md)] [[字符串](../string/README.md)] | Medium | | 1165 | [单行键盘](../../problems/single-row-keyboard) 🔒 | [[字符串](../string/README.md)] | Easy | | 1163 | [按字典序排在最后的子串](../../problems/last-substring-in-lexicographical-order) | [[字符串](../string/README.md)] | Hard | diff --git a/tag/tags.json b/tag/tags.json index dd04f1731..4ca263579 100644 --- a/tag/tags.json +++ b/tag/tags.json @@ -129,16 +129,16 @@ "Slug": "ordered-map", "TranslatedName": "Ordered Map" }, - { - "Name": "Geometry", - "Slug": "geometry", - "TranslatedName": "几何" - }, { "Name": "Queue", "Slug": "queue", "TranslatedName": "队列" }, + { + "Name": "Geometry", + "Slug": "geometry", + "TranslatedName": "几何" + }, { "Name": "Minimax", "Slug": "minimax", diff --git a/tag/tree/README.md b/tag/tree/README.md index a9e1b7c95..c99ee46d3 100644 --- a/tag/tree/README.md +++ b/tag/tree/README.md @@ -9,6 +9,7 @@ | # | 题目 | 标签 | 难度 | | :-: | - | - | :-: | +| 1740 | [Find Distance in a Binary Tree](../../problems/find-distance-in-a-binary-tree) 🔒 | [[树](../tree/README.md)] [[深度优先搜索](../depth-first-search/README.md)] [[广度优先搜索](../breadth-first-search/README.md)] | Easy | | 1719 | [重构一棵树的方案数](../../problems/number-of-ways-to-reconstruct-a-tree) | [[树](../tree/README.md)] [[图](../graph/README.md)] | Hard | | 1676 | [二叉树的最近公共祖先 IV](../../problems/lowest-common-ancestor-of-a-binary-tree-iv) 🔒 | [[树](../tree/README.md)] [[深度优先搜索](../depth-first-search/README.md)] | Medium | | 1666 | [改变二叉树的根节点](../../problems/change-the-root-of-a-binary-tree) 🔒 | [[树](../tree/README.md)] [[深度优先搜索](../depth-first-search/README.md)] | Medium | @@ -83,7 +84,7 @@ | 685 | [冗余连接 II](../../problems/redundant-connection-ii) | [[树](../tree/README.md)] [[深度优先搜索](../depth-first-search/README.md)] [[并查集](../union-find/README.md)] [[图](../graph/README.md)] | Hard | | 684 | [冗余连接](../../problems/redundant-connection) | [[树](../tree/README.md)] [[并查集](../union-find/README.md)] [[图](../graph/README.md)] | Medium | | 671 | [二叉树中第二小的节点](../../problems/second-minimum-node-in-a-binary-tree) | [[树](../tree/README.md)] | Easy | -| 669 | [修剪二叉搜索树](../../problems/trim-a-binary-search-tree) | [[树](../tree/README.md)] | Easy | +| 669 | [修剪二叉搜索树](../../problems/trim-a-binary-search-tree) | [[树](../tree/README.md)] [[递归](../recursion/README.md)] | Medium | | 666 | [路径和 IV](../../problems/path-sum-iv) 🔒 | [[树](../tree/README.md)] | Medium | | 663 | [均匀树划分](../../problems/equal-tree-partition) 🔒 | [[树](../tree/README.md)] | Medium | | 662 | [二叉树最大宽度](../../problems/maximum-width-of-binary-tree) | [[树](../tree/README.md)] | Medium | diff --git a/tag/trie/README.md b/tag/trie/README.md index 0e2a77cce..1269938dc 100644 --- a/tag/trie/README.md +++ b/tag/trie/README.md @@ -27,5 +27,5 @@ | 421 | [数组中两个数的最大异或值](../../problems/maximum-xor-of-two-numbers-in-an-array) | [[位运算](../bit-manipulation/README.md)] [[字典树](../trie/README.md)] | Medium | | 336 | [回文对](../../problems/palindrome-pairs) | [[字典树](../trie/README.md)] [[哈希表](../hash-table/README.md)] [[字符串](../string/README.md)] | Hard | | 212 | [单词搜索 II](../../problems/word-search-ii) | [[字典树](../trie/README.md)] [[回溯算法](../backtracking/README.md)] | Hard | -| 211 | [添加与搜索单词 - 数据结构设计](../../problems/design-add-and-search-words-data-structure) | [[设计](../design/README.md)] [[字典树](../trie/README.md)] [[回溯算法](../backtracking/README.md)] | Medium | +| 211 | [添加与搜索单词 - 数据结构设计](../../problems/design-add-and-search-words-data-structure) | [[深度优先搜索](../depth-first-search/README.md)] [[设计](../design/README.md)] [[字典树](../trie/README.md)] [[回溯算法](../backtracking/README.md)] | Medium | | 208 | [实现 Trie (前缀树)](../../problems/implement-trie-prefix-tree) | [[设计](../design/README.md)] [[字典树](../trie/README.md)] | Medium | diff --git a/tag/two-pointers/README.md b/tag/two-pointers/README.md index 71fdc75ca..e14c8fe4e 100644 --- a/tag/two-pointers/README.md +++ b/tag/two-pointers/README.md @@ -13,12 +13,13 @@ | 1711 | [大餐计数](../../problems/count-good-meals) | [[数组](../array/README.md)] [[哈希表](../hash-table/README.md)] [[双指针](../two-pointers/README.md)] | Medium | | 1695 | [删除子数组的最大得分](../../problems/maximum-erasure-value) | [[双指针](../two-pointers/README.md)] | Medium | | 1687 | [从仓库到码头运输箱子](../../problems/delivering-boxes-from-storage-to-ports) | [[线段树](../segment-tree/README.md)] [[双指针](../two-pointers/README.md)] [[动态规划](../dynamic-programming/README.md)] | Hard | -| 1658 | [将 x 减到 0 的最小操作数](../../problems/minimum-operations-to-reduce-x-to-zero) | [[贪心算法](../greedy/README.md)] [[双指针](../two-pointers/README.md)] [[二分查找](../binary-search/README.md)] | Medium | +| 1658 | [将 x 减到 0 的最小操作数](../../problems/minimum-operations-to-reduce-x-to-zero) | [[贪心算法](../greedy/README.md)] [[双指针](../two-pointers/README.md)] [[二分查找](../binary-search/README.md)] [[Sliding Window](../sliding-window/README.md)] | Medium | | 1616 | [分割两个字符串得到回文串](../../problems/split-two-strings-to-make-palindrome) | [[贪心算法](../greedy/README.md)] [[双指针](../two-pointers/README.md)] [[字符串](../string/README.md)] | Medium | | 1610 | [可见点的最大数目](../../problems/maximum-number-of-visible-points) | [[几何](../geometry/README.md)] [[双指针](../two-pointers/README.md)] | Hard | | 1570 | [两个稀疏向量的点积](../../problems/dot-product-of-two-sparse-vectors) 🔒 | [[数组](../array/README.md)] [[哈希表](../hash-table/README.md)] [[双指针](../two-pointers/README.md)] | Medium | | 1248 | [统计「优美子数组」](../../problems/count-number-of-nice-subarrays) | [[双指针](../two-pointers/README.md)] | Medium | | 1234 | [替换子串得到平衡字符串](../../problems/replace-the-substring-for-balanced-string) | [[双指针](../two-pointers/README.md)] [[字符串](../string/README.md)] | Medium | +| 1229 | [安排会议日程](../../problems/meeting-scheduler) 🔒 | [[排序](../sort/README.md)] [[双指针](../two-pointers/README.md)] [[Line Sweep](../line-sweep/README.md)] | Medium | | 1213 | [三个有序数组的交集](../../problems/intersection-of-three-sorted-arrays) 🔒 | [[哈希表](../hash-table/README.md)] [[双指针](../two-pointers/README.md)] | Easy | | 1099 | [小于 K 的两数之和](../../problems/two-sum-less-than-k) 🔒 | [[排序](../sort/README.md)] [[数组](../array/README.md)] [[双指针](../two-pointers/README.md)] | Easy | | 1093 | [大样本统计](../../problems/statistics-from-a-large-sample) | [[数学](../math/README.md)] [[双指针](../two-pointers/README.md)] | Medium | @@ -69,12 +70,12 @@ | 76 | [最小覆盖子串](../../problems/minimum-window-substring) | [[哈希表](../hash-table/README.md)] [[双指针](../two-pointers/README.md)] [[字符串](../string/README.md)] [[Sliding Window](../sliding-window/README.md)] | Hard | | 75 | [颜色分类](../../problems/sort-colors) | [[排序](../sort/README.md)] [[数组](../array/README.md)] [[双指针](../two-pointers/README.md)] | Medium | | 61 | [旋转链表](../../problems/rotate-list) | [[链表](../linked-list/README.md)] [[双指针](../two-pointers/README.md)] | Medium | -| 42 | [接雨水](../../problems/trapping-rain-water) | [[栈](../stack/README.md)] [[数组](../array/README.md)] [[双指针](../two-pointers/README.md)] | Hard | +| 42 | [接雨水](../../problems/trapping-rain-water) | [[栈](../stack/README.md)] [[数组](../array/README.md)] [[双指针](../two-pointers/README.md)] [[动态规划](../dynamic-programming/README.md)] | Hard | | 30 | [串联所有单词的子串](../../problems/substring-with-concatenation-of-all-words) | [[哈希表](../hash-table/README.md)] [[双指针](../two-pointers/README.md)] [[字符串](../string/README.md)] | Hard | | 28 | [实现 strStr()](../../problems/implement-strstr) | [[双指针](../two-pointers/README.md)] [[字符串](../string/README.md)] | Easy | | 27 | [移除元素](../../problems/remove-element) | [[数组](../array/README.md)] [[双指针](../two-pointers/README.md)] | Easy | | 26 | [删除排序数组中的重复项](../../problems/remove-duplicates-from-sorted-array) | [[数组](../array/README.md)] [[双指针](../two-pointers/README.md)] | Easy | -| 19 | [删除链表的倒数第N个节点](../../problems/remove-nth-node-from-end-of-list) | [[链表](../linked-list/README.md)] [[双指针](../two-pointers/README.md)] | Medium | +| 19 | [删除链表的倒数第 N 个结点](../../problems/remove-nth-node-from-end-of-list) | [[链表](../linked-list/README.md)] [[双指针](../two-pointers/README.md)] | Medium | | 18 | [四数之和](../../problems/4sum) | [[数组](../array/README.md)] [[哈希表](../hash-table/README.md)] [[双指针](../two-pointers/README.md)] | Medium | | 16 | [最接近的三数之和](../../problems/3sum-closest) | [[数组](../array/README.md)] [[双指针](../two-pointers/README.md)] | Medium | | 15 | [三数之和](../../problems/3sum) | [[数组](../array/README.md)] [[双指针](../two-pointers/README.md)] | Medium | diff --git a/tag/union-find/README.md b/tag/union-find/README.md index de255cc71..bf4d14937 100644 --- a/tag/union-find/README.md +++ b/tag/union-find/README.md @@ -9,6 +9,7 @@ | # | 题目 | 标签 | 难度 | | :-: | - | - | :-: | +| 1724 | [Checking Existence of Edge Length Limited Paths II](../../problems/checking-existence-of-edge-length-limited-paths-ii) 🔒 | [[并查集](../union-find/README.md)] [[图](../graph/README.md)] [[动态规划](../dynamic-programming/README.md)] | Hard | | 1722 | [执行交换操作后的最小汉明距离](../../problems/minimize-hamming-distance-after-swap-operations) | [[贪心算法](../greedy/README.md)] [[深度优先搜索](../depth-first-search/README.md)] [[并查集](../union-find/README.md)] | Medium | | 1697 | [检查边长度限制的路径是否存在](../../problems/checking-existence-of-edge-length-limited-paths) | [[排序](../sort/README.md)] [[并查集](../union-find/README.md)] | Hard | | 1632 | [矩阵转换后的秩](../../problems/rank-transform-of-a-matrix) | [[贪心算法](../greedy/README.md)] [[并查集](../union-find/README.md)] | Hard |