Skip to content

Commit 574a257

Browse files
author
Shuo
committed
A: new
1 parent 38b080d commit 574a257

File tree

50 files changed

+1295
-174
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+1295
-174
lines changed

README.md

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,28 @@ LeetCode Problems' Solutions
6262

6363
| # | Title | Solution | Difficulty |
6464
| :-: | - | - | :-: |
65+
| <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 |
66+
| <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 |
67+
| <span id="1487">1487</span> | [Making File Names Unique](https://leetcode.com/problems/making-file-names-unique "保证文件名唯一") | [Go](problems/making-file-names-unique) | Medium |
68+
| <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 |
69+
| <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 |
70+
| <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 |
71+
| <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 |
72+
| <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 |
73+
| <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 |
74+
| <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 |
75+
| <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 |
76+
| <span id="1478">1478</span> | [Allocate Mailboxes](https://leetcode.com/problems/allocate-mailboxes "安排邮筒") | [Go](problems/allocate-mailboxes) | Hard |
77+
| <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 |
78+
| <span id="1476">1476</span> | [Subrectangle Queries](https://leetcode.com/problems/subrectangle-queries "子矩形查询") | [Go](problems/subrectangle-queries) | Medium |
79+
| <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 |
80+
| <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 |
6581
| <span id="1473">1473</span> | [Paint House III](https://leetcode.com/problems/paint-house-iii "给房子涂色 III") | [Go](problems/paint-house-iii) | Hard |
6682
| <span id="1472">1472</span> | [Design Browser History](https://leetcode.com/problems/design-browser-history "设计浏览器历史记录") | [Go](problems/design-browser-history) | Medium |
6783
| <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 |
6884
| <span id="1470">1470</span> | [Shuffle the Array](https://leetcode.com/problems/shuffle-the-array "重新排列数组") | [Go](problems/shuffle-the-array) | Easy |
6985
| <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 |
70-
| <span id="1468">1468</span> | [Calculate Salaries](https://leetcode.com/problems/calculate-salaries) 🔒 | [MySQL](problems/calculate-salaries) | Medium |
86+
| <span id="1468">1468</span> | [Calculate Salaries](https://leetcode.com/problems/calculate-salaries "计算税后工资") 🔒 | [MySQL](problems/calculate-salaries) | Medium |
7187
| <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 |
7288
| <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 |
7389
| <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 |
@@ -108,7 +124,7 @@ LeetCode Problems' Solutions
108124
| <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 |
109125
| <span id="1429">1429</span> | [First Unique Number](https://leetcode.com/problems/first-unique-number) 🔒 | [Go](problems/first-unique-number) | Medium |
110126
| <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 |
111-
| <span id="1427">1427</span> | [Perform String Shifts](https://leetcode.com/problems/perform-string-shifts) 🔒 | [Go](problems/perform-string-shifts) | Easy |
127+
| <span id="1427">1427</span> | [Perform String Shifts](https://leetcode.com/problems/perform-string-shifts "字符串的左右移") 🔒 | [Go](problems/perform-string-shifts) | Easy |
112128
| <span id="1426">1426</span> | [Counting Elements](https://leetcode.com/problems/counting-elements "数元素") 🔒 | [Go](problems/counting-elements) | Easy |
113129
| <span id="1425">1425</span> | [Constrained Subsequence Sum](https://leetcode.com/problems/constrained-subsequence-sum "带限制的子序列和") | [Go](problems/constrained-subsequence-sum) | Hard |
114130
| <span id="1424">1424</span> | [Diagonal Traverse II](https://leetcode.com/problems/diagonal-traverse-ii "对角线遍历 II") | [Go](problems/diagonal-traverse-ii) | Medium |
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
<!--|This file generated by command(leetcode description); DO NOT EDIT. |-->
2+
<!--+----------------------------------------------------------------------+-->
3+
<!--|@author openset <openset.wang@gmail.com> |-->
4+
<!--|@link https://github.com/openset |-->
5+
<!--|@home https://github.com/openset/leetcode |-->
6+
<!--+----------------------------------------------------------------------+-->
7+
8+
[< Previous](../find-two-non-overlapping-sub-arrays-each-with-target-sum "Find Two Non-overlapping Sub-arrays Each With Target Sum")
9+
                
10+
[Next >](../sales-by-day-of-the-week "Sales by Day of the Week")
11+
12+
## [1478. Allocate Mailboxes (Hard)](https://leetcode.com/problems/allocate-mailboxes "安排邮筒")
13+
14+
<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>
15+
16+
<p>Return the <strong>minimum</strong> total distance between each house and its nearest mailbox.</p>
17+
18+
<p>The answer is guaranteed to fit in a 32-bit signed integer.</p>
19+
20+
<p>&nbsp;</p>
21+
<p><strong>Example 1:</strong></p>
22+
23+
<p><img alt="" src="https://assets.leetcode.com/uploads/2020/05/07/sample_11_1816.png" style="width: 454px; height: 154px;" /></p>
24+
25+
<pre>
26+
<strong>Input:</strong> houses = [1,4,8,10,20], k = 3
27+
<strong>Output:</strong> 5
28+
<strong>Explanation: </strong>Allocate mailboxes in position 3, 9 and 20.
29+
Minimum total distance from each houses to nearest mailboxes is |3-1| + |4-3| + |9-8| + |10-9| + |20-20| = 5
30+
</pre>
31+
32+
<p><strong>Example 2:</strong></p>
33+
34+
<p><strong><img alt="" src="https://assets.leetcode.com/uploads/2020/05/07/sample_2_1816.png" style="width: 433px; height: 154px;" /></strong></p>
35+
36+
<pre>
37+
<strong>Input:</strong> houses = [2,3,5,12,18], k = 2
38+
<strong>Output:</strong> 9
39+
<strong>Explanation: </strong>Allocate mailboxes in position 3 and 14.
40+
Minimum total distance from each houses to nearest mailboxes is |2-3| + |3-3| + |5-3| + |12-14| + |18-14| = 9.
41+
</pre>
42+
43+
<p><strong>Example 3:</strong></p>
44+
45+
<pre>
46+
<strong>Input:</strong> houses = [7,4,6,1], k = 1
47+
<strong>Output:</strong> 8
48+
</pre>
49+
50+
<p><strong>Example 4:</strong></p>
51+
52+
<pre>
53+
<strong>Input:</strong> houses = [3,6,14,10], k = 4
54+
<strong>Output:</strong> 0
55+
</pre>
56+
57+
<p>&nbsp;</p>
58+
<p><strong>Constraints:</strong></p>
59+
60+
<ul>
61+
<li><code>n == houses.length</code></li>
62+
<li><code>1 &lt;= n&nbsp;&lt;= 100</code></li>
63+
<li><code>1 &lt;= houses[i] &lt;= 10^4</code></li>
64+
<li><code>1 &lt;= k &lt;= n</code></li>
65+
<li>Array <code>houses</code> contain unique integers.</li>
66+
</ul>
67+
68+
### Related Topics
69+
[[Math](../../tag/math/README.md)]
70+
[[Dynamic Programming](../../tag/dynamic-programming/README.md)]
71+
72+
### Hints
73+
<details>
74+
<summary>Hint 1</summary>
75+
If k =1, the minimum distance is obtained allocating the mailbox in the median of the array houses.
76+
</details>
77+
78+
<details>
79+
<summary>Hint 2</summary>
80+
Generalize this idea, using dynamic programming allocating k mailboxes.
81+
</details>
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
<!--|This file generated by command(leetcode description); DO NOT EDIT. |-->
2+
<!--+----------------------------------------------------------------------+-->
3+
<!--|@author openset <openset.wang@gmail.com> |-->
4+
<!--|@link https://github.com/openset |-->
5+
<!--|@home https://github.com/openset/leetcode |-->
6+
<!--+----------------------------------------------------------------------+-->
7+
8+
[< Previous](../making-file-names-unique "Making File Names Unique")
9+
                
10+
[Next >](../find-critical-and-pseudo-critical-edges-in-minimum-spanning-tree "Find Critical and Pseudo-Critical Edges in Minimum Spanning Tree")
11+
12+
## [1488. Avoid Flood in The City (Medium)](https://leetcode.com/problems/avoid-flood-in-the-city "避免洪水泛滥")
13+
14+
<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>
15+
16+
<p>Given an integer array <code>rains</code> where:</p>
17+
18+
<ul>
19+
<li><code>rains[i] &gt; 0</code> means there will be rains over the <code>rains[i]</code> lake.</li>
20+
<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>
21+
</ul>
22+
23+
<p>Return <em>an array <code>ans</code></em> where:</p>
24+
25+
<ul>
26+
<li><code>ans.length == rains.length</code></li>
27+
<li><code>ans[i] == -1</code> if <code>rains[i] &gt; 0</code>.</li>
28+
<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>
29+
</ul>
30+
31+
<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>
32+
33+
<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>
34+
35+
<p>&nbsp;</p>
36+
<p><strong>Example 1:</strong></p>
37+
38+
<pre>
39+
<strong>Input:</strong> rains = [1,2,3,4]
40+
<strong>Output:</strong> [-1,-1,-1,-1]
41+
<strong>Explanation:</strong> After the first day full lakes are [1]
42+
After the second day full lakes are [1,2]
43+
After the third day full lakes are [1,2,3]
44+
After the fourth day full lakes are [1,2,3,4]
45+
There&#39;s no day to dry any lake and there is no flood in any lake.
46+
</pre>
47+
48+
<p><strong>Example 2:</strong></p>
49+
50+
<pre>
51+
<strong>Input:</strong> rains = [1,2,0,0,2,1]
52+
<strong>Output:</strong> [-1,-1,2,1,-1,-1]
53+
<strong>Explanation:</strong> After the first day full lakes are [1]
54+
After the second day full lakes are [1,2]
55+
After the third day, we dry lake 2. Full lakes are [1]
56+
After the fourth day, we dry lake 1. There is no full lakes.
57+
After the fifth day, full lakes are [2].
58+
After the sixth day, full lakes are [1,2].
59+
It is easy that this scenario is flood-free. [-1,-1,1,2,-1,-1] is another acceptable scenario.
60+
</pre>
61+
62+
<p><strong>Example 3:</strong></p>
63+
64+
<pre>
65+
<strong>Input:</strong> rains = [1,2,0,1,2]
66+
<strong>Output:</strong> []
67+
<strong>Explanation:</strong> After the second day, full lakes are [1,2]. We have to dry one lake in the third day.
68+
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.
69+
</pre>
70+
71+
<p><strong>Example 4:</strong></p>
72+
73+
<pre>
74+
<strong>Input:</strong> rains = [69,0,0,0,69]
75+
<strong>Output:</strong> [-1,69,1,1,-1]
76+
<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
77+
</pre>
78+
79+
<p><strong>Example 5:</strong></p>
80+
81+
<pre>
82+
<strong>Input:</strong> rains = [10,20,20]
83+
<strong>Output:</strong> []
84+
<strong>Explanation:</strong> It will rain over lake 20 two consecutive days. There is no chance to dry any lake.
85+
</pre>
86+
87+
<p>&nbsp;</p>
88+
<p><strong>Constraints:</strong></p>
89+
90+
<ul>
91+
<li><code>1 &lt;= rains.length &lt;= 10^5</code></li>
92+
<li><code>0 &lt;= rains[i] &lt;= 10^9</code></li>
93+
</ul>
94+
95+
### Related Topics
96+
[[Array](../../tag/array/README.md)]
97+
[[Hash Table](../../tag/hash-table/README.md)]
98+
99+
### Hints
100+
<details>
101+
<summary>Hint 1</summary>
102+
Keep An array of the last day there was rains over each city.
103+
</details>
104+
105+
<details>
106+
<summary>Hint 2</summary>
107+
Keep an array of the days you can dry a lake when you face one.
108+
</details>
109+
110+
<details>
111+
<summary>Hint 3</summary>
112+
When it rains over a lake, check the first possible day you can dry this lake and assign this day to this lake.
113+
</details>

problems/calculate-salaries/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@
99

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

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

1414

problems/capacity-to-ship-packages-within-d-days/README.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,12 @@ A ship capacity of 6 is the minimum to ship all the packages in 3 days like this
6060
</pre>
6161

6262
<p>&nbsp;</p>
63+
<p><strong>Constraints:</strong></p>
6364

64-
<p><strong>Note:</strong></p>
65-
66-
<ol>
65+
<ul>
6766
<li><code>1 &lt;= D &lt;= weights.length &lt;= 50000</code></li>
6867
<li><code>1 &lt;= weights[i] &lt;= 500</code></li>
69-
</ol>
68+
</ul>
7069

7170
### Related Topics
7271
[[Array](../../tag/array/README.md)]

problems/check-if-a-string-contains-all-binary-codes-of-size-k/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

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

16-
<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>
16+
<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>
1717

1818
<p>&nbsp;</p>
1919
<p><strong>Example 1:</strong></p>
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<!--|This file generated by command(leetcode description); DO NOT EDIT. |-->
2+
<!--+----------------------------------------------------------------------+-->
3+
<!--|@author openset <openset.wang@gmail.com> |-->
4+
<!--|@link https://github.com/openset |-->
5+
<!--|@home https://github.com/openset/leetcode |-->
6+
<!--+----------------------------------------------------------------------+-->
7+
8+
[< Previous](../group-sold-products-by-the-date "Group Sold Products By The Date")
9+
                
10+
[Next >](../xor-operation-in-an-array "XOR Operation in an Array")
11+
12+
## [1485. Clone Binary Tree With Random Pointer (Medium)](https://leetcode.com/problems/clone-binary-tree-with-random-pointer "克隆含随机指针的二叉树")
13+
14+
15+
16+
### Related Topics
17+
[[Tree](../../tag/tree/README.md)]
18+
[[Depth-first Search](../../tag/depth-first-search/README.md)]
19+
20+
### Hints
21+
<details>
22+
<summary>Hint 1</summary>
23+
Create an equivalent node for each node in the original tree.
24+
</details>
25+
26+
<details>
27+
<summary>Hint 2</summary>
28+
Start traversing the original tree and connect the left, right and random pointers in the cloned tree the same way as the original tree.
29+
</details>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<!--|This file generated by command(leetcode description); DO NOT EDIT. |-->
2+
<!--+----------------------------------------------------------------------+-->
3+
<!--|@author openset <openset.wang@gmail.com> |-->
4+
<!--|@link https://github.com/openset |-->
5+
<!--|@home https://github.com/openset/leetcode |-->
6+
<!--+----------------------------------------------------------------------+-->
7+
8+
[< Previous](../paint-house-iii "Paint House III")
9+
                
10+
[Next >](../final-prices-with-a-special-discount-in-a-shop "Final Prices With a Special Discount in a Shop")
11+
12+
## [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 个节点")
13+
14+
15+
16+
### Related Topics
17+
[[Linked List](../../tag/linked-list/README.md)]

problems/expression-add-operators/README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,14 @@
4646
<b>Output: </b>[]
4747
</pre>
4848

49+
<p>&nbsp;</p>
50+
<p><strong>Constraints:</strong></p>
51+
52+
<ul>
53+
<li><code>0 &lt;= num.length &lt;= 10</code></li>
54+
<li><code>num</code> only contain&nbsp;digits.</li>
55+
</ul>
56+
4957
### Related Topics
5058
[[Divide and Conquer](../../tag/divide-and-conquer/README.md)]
5159

0 commit comments

Comments
 (0)