Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,28 @@ LeetCode Problems' Solutions

| # | Title | Solution | Difficulty |
| :-: | - | - | :-: |
| <span id="1489">1489</span> | [Find Critical and Pseudo-Critical Edges in Minimum Spanning Tree](https://leetcode.com/problems/find-critical-and-pseudo-critical-edges-in-minimum-spanning-tree "找到最小生成树里的关键边和伪关键边") | [Go](problems/find-critical-and-pseudo-critical-edges-in-minimum-spanning-tree) | Hard |
| <span id="1488">1488</span> | [Avoid Flood in The City](https://leetcode.com/problems/avoid-flood-in-the-city "避免洪水泛滥") | [Go](problems/avoid-flood-in-the-city) | Medium |
| <span id="1487">1487</span> | [Making File Names Unique](https://leetcode.com/problems/making-file-names-unique "保证文件名唯一") | [Go](problems/making-file-names-unique) | Medium |
| <span id="1486">1486</span> | [XOR Operation in an Array](https://leetcode.com/problems/xor-operation-in-an-array "数组异或操作") | [Go](problems/xor-operation-in-an-array) | Easy |
| <span id="1485">1485</span> | [Clone Binary Tree With Random Pointer](https://leetcode.com/problems/clone-binary-tree-with-random-pointer "克隆含随机指针的二叉树") 🔒 | [Go](problems/clone-binary-tree-with-random-pointer) | Medium |
| <span id="1484">1484</span> | [Group Sold Products By The Date](https://leetcode.com/problems/group-sold-products-by-the-date) 🔒 | [MySQL](problems/group-sold-products-by-the-date) | Easy |
| <span id="1483">1483</span> | [Kth Ancestor of a Tree Node](https://leetcode.com/problems/kth-ancestor-of-a-tree-node "树节点的第 K 个祖先") | [Go](problems/kth-ancestor-of-a-tree-node) | Hard |
| <span id="1482">1482</span> | [Minimum Number of Days to Make m Bouquets](https://leetcode.com/problems/minimum-number-of-days-to-make-m-bouquets "制作 m 束花所需的最少天数") | [Go](problems/minimum-number-of-days-to-make-m-bouquets) | Medium |
| <span id="1481">1481</span> | [Least Number of Unique Integers after K Removals](https://leetcode.com/problems/least-number-of-unique-integers-after-k-removals "不同整数的最少数目") | [Go](problems/least-number-of-unique-integers-after-k-removals) | Medium |
| <span id="1480">1480</span> | [Running Sum of 1d Array](https://leetcode.com/problems/running-sum-of-1d-array "一维数组的动态和") | [Go](problems/running-sum-of-1d-array) | Easy |
| <span id="1479">1479</span> | [Sales by Day of the Week](https://leetcode.com/problems/sales-by-day-of-the-week) 🔒 | [MySQL](problems/sales-by-day-of-the-week) | Hard |
| <span id="1478">1478</span> | [Allocate Mailboxes](https://leetcode.com/problems/allocate-mailboxes "安排邮筒") | [Go](problems/allocate-mailboxes) | Hard |
| <span id="1477">1477</span> | [Find Two Non-overlapping Sub-arrays Each With Target Sum](https://leetcode.com/problems/find-two-non-overlapping-sub-arrays-each-with-target-sum "找两个和为目标值且不重叠的子数组") | [Go](problems/find-two-non-overlapping-sub-arrays-each-with-target-sum) | Medium |
| <span id="1476">1476</span> | [Subrectangle Queries](https://leetcode.com/problems/subrectangle-queries "子矩形查询") | [Go](problems/subrectangle-queries) | Medium |
| <span id="1475">1475</span> | [Final Prices With a Special Discount in a Shop](https://leetcode.com/problems/final-prices-with-a-special-discount-in-a-shop "商品折扣后的最终价格") | [Go](problems/final-prices-with-a-special-discount-in-a-shop) | Easy |
| <span id="1474">1474</span> | [Delete N Nodes After M Nodes of a Linked List](https://leetcode.com/problems/delete-n-nodes-after-m-nodes-of-a-linked-list "删除链表 M 个节点之后的 N 个节点") 🔒 | [Go](problems/delete-n-nodes-after-m-nodes-of-a-linked-list) | Easy |
| <span id="1473">1473</span> | [Paint House III](https://leetcode.com/problems/paint-house-iii "给房子涂色 III") | [Go](problems/paint-house-iii) | Hard |
| <span id="1472">1472</span> | [Design Browser History](https://leetcode.com/problems/design-browser-history "设计浏览器历史记录") | [Go](problems/design-browser-history) | Medium |
| <span id="1471">1471</span> | [The k Strongest Values in an Array](https://leetcode.com/problems/the-k-strongest-values-in-an-array "数组中的 k 个最强值") | [Go](problems/the-k-strongest-values-in-an-array) | Medium |
| <span id="1470">1470</span> | [Shuffle the Array](https://leetcode.com/problems/shuffle-the-array "重新排列数组") | [Go](problems/shuffle-the-array) | Easy |
| <span id="1469">1469</span> | [Find All The Lonely Nodes](https://leetcode.com/problems/find-all-the-lonely-nodes) 🔒 | [Go](problems/find-all-the-lonely-nodes) | Easy |
| <span id="1468">1468</span> | [Calculate Salaries](https://leetcode.com/problems/calculate-salaries) 🔒 | [MySQL](problems/calculate-salaries) | Medium |
| <span id="1468">1468</span> | [Calculate Salaries](https://leetcode.com/problems/calculate-salaries "计算税后工资") 🔒 | [MySQL](problems/calculate-salaries) | Medium |
| <span id="1467">1467</span> | [Probability of a Two Boxes Having The Same Number of Distinct Balls](https://leetcode.com/problems/probability-of-a-two-boxes-having-the-same-number-of-distinct-balls "两个盒子中球的颜色数相同的概率") | [Go](problems/probability-of-a-two-boxes-having-the-same-number-of-distinct-balls) | Hard |
| <span id="1466">1466</span> | [Reorder Routes to Make All Paths Lead to the City Zero](https://leetcode.com/problems/reorder-routes-to-make-all-paths-lead-to-the-city-zero "重新规划路线") | [Go](problems/reorder-routes-to-make-all-paths-lead-to-the-city-zero) | Medium |
| <span id="1465">1465</span> | [Maximum Area of a Piece of Cake After Horizontal and Vertical Cuts](https://leetcode.com/problems/maximum-area-of-a-piece-of-cake-after-horizontal-and-vertical-cuts "切割后面积最大的蛋糕") | [Go](problems/maximum-area-of-a-piece-of-cake-after-horizontal-and-vertical-cuts) | Medium |
Expand Down Expand Up @@ -108,7 +124,7 @@ LeetCode Problems' Solutions
| <span id="1430">1430</span> | [Check If a String Is a Valid Sequence from Root to Leaves Path in a Binary Tree](https://leetcode.com/problems/check-if-a-string-is-a-valid-sequence-from-root-to-leaves-path-in-a-binary-tree) 🔒 | [Go](problems/check-if-a-string-is-a-valid-sequence-from-root-to-leaves-path-in-a-binary-tree) | Medium |
| <span id="1429">1429</span> | [First Unique Number](https://leetcode.com/problems/first-unique-number) 🔒 | [Go](problems/first-unique-number) | Medium |
| <span id="1428">1428</span> | [Leftmost Column with at Least a One](https://leetcode.com/problems/leftmost-column-with-at-least-a-one "至少有一个 1 的最左端列") 🔒 | [Go](problems/leftmost-column-with-at-least-a-one) | Medium |
| <span id="1427">1427</span> | [Perform String Shifts](https://leetcode.com/problems/perform-string-shifts) 🔒 | [Go](problems/perform-string-shifts) | Easy |
| <span id="1427">1427</span> | [Perform String Shifts](https://leetcode.com/problems/perform-string-shifts "字符串的左右移") 🔒 | [Go](problems/perform-string-shifts) | Easy |
| <span id="1426">1426</span> | [Counting Elements](https://leetcode.com/problems/counting-elements "数元素") 🔒 | [Go](problems/counting-elements) | Easy |
| <span id="1425">1425</span> | [Constrained Subsequence Sum](https://leetcode.com/problems/constrained-subsequence-sum "带限制的子序列和") | [Go](problems/constrained-subsequence-sum) | Hard |
| <span id="1424">1424</span> | [Diagonal Traverse II](https://leetcode.com/problems/diagonal-traverse-ii "对角线遍历 II") | [Go](problems/diagonal-traverse-ii) | Medium |
Expand Down
81 changes: 81 additions & 0 deletions problems/allocate-mailboxes/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<!--|This file generated by command(leetcode description); DO NOT EDIT. |-->
<!--+----------------------------------------------------------------------+-->
<!--|@author openset <openset.wang@gmail.com> |-->
<!--|@link https://github.com/openset |-->
<!--|@home https://github.com/openset/leetcode |-->
<!--+----------------------------------------------------------------------+-->

[< Previous](../find-two-non-overlapping-sub-arrays-each-with-target-sum "Find Two Non-overlapping Sub-arrays Each With Target Sum")

[Next >](../sales-by-day-of-the-week "Sales by Day of the Week")

## [1478. Allocate Mailboxes (Hard)](https://leetcode.com/problems/allocate-mailboxes "安排邮筒")

<p>Given the array <code>houses</code> and an integer <code>k</code>. where <code>houses[i]</code> is the location of the ith house along a street, your task is to allocate <code>k</code> mailboxes in&nbsp;the street.</p>

<p>Return the <strong>minimum</strong> total distance between each house and its nearest mailbox.</p>

<p>The answer is guaranteed to fit in a 32-bit signed integer.</p>

<p>&nbsp;</p>
<p><strong>Example 1:</strong></p>

<p><img alt="" src="https://assets.leetcode.com/uploads/2020/05/07/sample_11_1816.png" style="width: 454px; height: 154px;" /></p>

<pre>
<strong>Input:</strong> houses = [1,4,8,10,20], k = 3
<strong>Output:</strong> 5
<strong>Explanation: </strong>Allocate mailboxes in position 3, 9 and 20.
Minimum total distance from each houses to nearest mailboxes is |3-1| + |4-3| + |9-8| + |10-9| + |20-20| = 5
</pre>

<p><strong>Example 2:</strong></p>

<p><strong><img alt="" src="https://assets.leetcode.com/uploads/2020/05/07/sample_2_1816.png" style="width: 433px; height: 154px;" /></strong></p>

<pre>
<strong>Input:</strong> houses = [2,3,5,12,18], k = 2
<strong>Output:</strong> 9
<strong>Explanation: </strong>Allocate mailboxes in position 3 and 14.
Minimum total distance from each houses to nearest mailboxes is |2-3| + |3-3| + |5-3| + |12-14| + |18-14| = 9.
</pre>

<p><strong>Example 3:</strong></p>

<pre>
<strong>Input:</strong> houses = [7,4,6,1], k = 1
<strong>Output:</strong> 8
</pre>

<p><strong>Example 4:</strong></p>

<pre>
<strong>Input:</strong> houses = [3,6,14,10], k = 4
<strong>Output:</strong> 0
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
<li><code>n == houses.length</code></li>
<li><code>1 &lt;= n&nbsp;&lt;= 100</code></li>
<li><code>1 &lt;= houses[i] &lt;= 10^4</code></li>
<li><code>1 &lt;= k &lt;= n</code></li>
<li>Array <code>houses</code> contain unique integers.</li>
</ul>

### Related Topics
[[Math](../../tag/math/README.md)]
[[Dynamic Programming](../../tag/dynamic-programming/README.md)]

### Hints
<details>
<summary>Hint 1</summary>
If k =1, the minimum distance is obtained allocating the mailbox in the median of the array houses.
</details>

<details>
<summary>Hint 2</summary>
Generalize this idea, using dynamic programming allocating k mailboxes.
</details>
113 changes: 113 additions & 0 deletions problems/avoid-flood-in-the-city/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
<!--|This file generated by command(leetcode description); DO NOT EDIT. |-->
<!--+----------------------------------------------------------------------+-->
<!--|@author openset <openset.wang@gmail.com> |-->
<!--|@link https://github.com/openset |-->
<!--|@home https://github.com/openset/leetcode |-->
<!--+----------------------------------------------------------------------+-->

[< Previous](../making-file-names-unique "Making File Names Unique")

[Next >](../find-critical-and-pseudo-critical-edges-in-minimum-spanning-tree "Find Critical and Pseudo-Critical Edges in Minimum Spanning Tree")

## [1488. Avoid Flood in The City (Medium)](https://leetcode.com/problems/avoid-flood-in-the-city "避免洪水泛滥")

<p>Your country has an infinite number of lakes. Initially, all the lakes are empty, but when it rains over the <code>nth</code> lake, the <code>nth</code> lake becomes full of water. If it rains over a lake which is <strong>full of water</strong>, there will be a <strong>flood</strong>. Your goal is to avoid the flood in any lake.</p>

<p>Given an integer array <code>rains</code> where:</p>

<ul>
<li><code>rains[i] &gt; 0</code> means there will be rains over the <code>rains[i]</code> lake.</li>
<li><code>rains[i] == 0</code> means there are no rains this day and you can choose <strong>one lake</strong> this day and <strong>dry it</strong>.</li>
</ul>

<p>Return <em>an array <code>ans</code></em> where:</p>

<ul>
<li><code>ans.length == rains.length</code></li>
<li><code>ans[i] == -1</code> if <code>rains[i] &gt; 0</code>.</li>
<li><code>ans[i]</code> is the lake you choose to dry in the <code>ith</code> day&nbsp;if <code>rains[i] == 0</code>.</li>
</ul>

<p>If there are multiple valid answers return <strong>any</strong> of them. If it is impossible to avoid flood return <strong>an empty array</strong>.</p>

<p>Notice that if you chose to dry a full lake, it becomes empty, but if you chose to dry an empty lake, nothing changes. (see example 4)</p>

<p>&nbsp;</p>
<p><strong>Example 1:</strong></p>

<pre>
<strong>Input:</strong> rains = [1,2,3,4]
<strong>Output:</strong> [-1,-1,-1,-1]
<strong>Explanation:</strong> After the first day full lakes are [1]
After the second day full lakes are [1,2]
After the third day full lakes are [1,2,3]
After the fourth day full lakes are [1,2,3,4]
There&#39;s no day to dry any lake and there is no flood in any lake.
</pre>

<p><strong>Example 2:</strong></p>

<pre>
<strong>Input:</strong> rains = [1,2,0,0,2,1]
<strong>Output:</strong> [-1,-1,2,1,-1,-1]
<strong>Explanation:</strong> After the first day full lakes are [1]
After the second day full lakes are [1,2]
After the third day, we dry lake 2. Full lakes are [1]
After the fourth day, we dry lake 1. There is no full lakes.
After the fifth day, full lakes are [2].
After the sixth day, full lakes are [1,2].
It is easy that this scenario is flood-free. [-1,-1,1,2,-1,-1] is another acceptable scenario.
</pre>

<p><strong>Example 3:</strong></p>

<pre>
<strong>Input:</strong> rains = [1,2,0,1,2]
<strong>Output:</strong> []
<strong>Explanation:</strong> After the second day, full lakes are [1,2]. We have to dry one lake in the third day.
After that, it will rain over lakes [1,2]. It&#39;s easy to prove that no matter which lake you choose to dry in the 3rd day, the other one will flood.
</pre>

<p><strong>Example 4:</strong></p>

<pre>
<strong>Input:</strong> rains = [69,0,0,0,69]
<strong>Output:</strong> [-1,69,1,1,-1]
<strong>Explanation:</strong> Any solution on one of the forms [-1,69,x,y,-1], [-1,x,69,y,-1] or [-1,x,y,69,-1] is acceptable where 1 &lt;= x,y &lt;= 10^9
</pre>

<p><strong>Example 5:</strong></p>

<pre>
<strong>Input:</strong> rains = [10,20,20]
<strong>Output:</strong> []
<strong>Explanation:</strong> It will rain over lake 20 two consecutive days. There is no chance to dry any lake.
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
<li><code>1 &lt;= rains.length &lt;= 10^5</code></li>
<li><code>0 &lt;= rains[i] &lt;= 10^9</code></li>
</ul>

### Related Topics
[[Array](../../tag/array/README.md)]
[[Hash Table](../../tag/hash-table/README.md)]

### Hints
<details>
<summary>Hint 1</summary>
Keep An array of the last day there was rains over each city.
</details>

<details>
<summary>Hint 2</summary>
Keep an array of the days you can dry a lake when you face one.
</details>

<details>
<summary>Hint 3</summary>
When it rains over a lake, check the first possible day you can dry this lake and assign this day to this lake.
</details>
2 changes: 1 addition & 1 deletion problems/calculate-salaries/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@

[Next >](../find-all-the-lonely-nodes "Find All The Lonely Nodes")

## [1468. Calculate Salaries (Medium)](https://leetcode.com/problems/calculate-salaries "")
## [1468. Calculate Salaries (Medium)](https://leetcode.com/problems/calculate-salaries "计算税后工资")


7 changes: 3 additions & 4 deletions problems/capacity-to-ship-packages-within-d-days/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,12 @@ A ship capacity of 6 is the minimum to ship all the packages in 3 days like this
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<p><strong>Note:</strong></p>

<ol>
<ul>
<li><code>1 &lt;= D &lt;= weights.length &lt;= 50000</code></li>
<li><code>1 &lt;= weights[i] &lt;= 500</code></li>
</ol>
</ul>

### Related Topics
[[Array](../../tag/array/README.md)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

<p>Given a binary string <code>s</code> and an integer <code>k</code>.</p>

<p>Return <em>True</em> if all binary codes of length <code>k</code> is a substring of <code>s</code>. Otherwise, return <em>False</em>.</p>
<p>Return <em>True</em> if every&nbsp;binary code&nbsp;of length <code>k</code> is a substring of <code>s</code>. Otherwise, return <em>False</em>.</p>

<p>&nbsp;</p>
<p><strong>Example 1:</strong></p>
Expand Down
29 changes: 29 additions & 0 deletions problems/clone-binary-tree-with-random-pointer/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<!--|This file generated by command(leetcode description); DO NOT EDIT. |-->
<!--+----------------------------------------------------------------------+-->
<!--|@author openset <openset.wang@gmail.com> |-->
<!--|@link https://github.com/openset |-->
<!--|@home https://github.com/openset/leetcode |-->
<!--+----------------------------------------------------------------------+-->

[< Previous](../group-sold-products-by-the-date "Group Sold Products By The Date")

[Next >](../xor-operation-in-an-array "XOR Operation in an Array")

## [1485. Clone Binary Tree With Random Pointer (Medium)](https://leetcode.com/problems/clone-binary-tree-with-random-pointer "克隆含随机指针的二叉树")



### Related Topics
[[Tree](../../tag/tree/README.md)]
[[Depth-first Search](../../tag/depth-first-search/README.md)]

### Hints
<details>
<summary>Hint 1</summary>
Create an equivalent node for each node in the original tree.
</details>

<details>
<summary>Hint 2</summary>
Start traversing the original tree and connect the left, right and random pointers in the cloned tree the same way as the original tree.
</details>
17 changes: 17 additions & 0 deletions problems/delete-n-nodes-after-m-nodes-of-a-linked-list/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!--|This file generated by command(leetcode description); DO NOT EDIT. |-->
<!--+----------------------------------------------------------------------+-->
<!--|@author openset <openset.wang@gmail.com> |-->
<!--|@link https://github.com/openset |-->
<!--|@home https://github.com/openset/leetcode |-->
<!--+----------------------------------------------------------------------+-->

[< Previous](../paint-house-iii "Paint House III")

[Next >](../final-prices-with-a-special-discount-in-a-shop "Final Prices With a Special Discount in a Shop")

## [1474. Delete N Nodes After M Nodes of a Linked List (Easy)](https://leetcode.com/problems/delete-n-nodes-after-m-nodes-of-a-linked-list "删除链表 M 个节点之后的 N 个节点")



### Related Topics
[[Linked List](../../tag/linked-list/README.md)]
8 changes: 8 additions & 0 deletions problems/expression-add-operators/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@
<b>Output: </b>[]
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
<li><code>0 &lt;= num.length &lt;= 10</code></li>
<li><code>num</code> only contain&nbsp;digits.</li>
</ul>

### Related Topics
[[Divide and Conquer](../../tag/divide-and-conquer/README.md)]

Expand Down
Loading