Skip to content

Commit 18de5fd

Browse files
author
Shuo
committed
A: new
1 parent 521a6c1 commit 18de5fd

File tree

112 files changed

+3334
-1038
lines changed

Some content is hidden

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

112 files changed

+3334
-1038
lines changed

README.md

+24
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,30 @@ LeetCode Problems' Solutions
7070

7171
| # | Title | Solution | Difficulty |
7272
| :-: | - | - | :-: |
73+
| <span id="1771">1771</span> | [Maximize Palindrome Length From Subsequences](https://leetcode.com/problems/maximize-palindrome-length-from-subsequences "由子序列构造的最长回文串的长度") | [Go](problems/maximize-palindrome-length-from-subsequences) | Hard |
74+
| <span id="1770">1770</span> | [Maximum Score from Performing Multiplication Operations](https://leetcode.com/problems/maximum-score-from-performing-multiplication-operations "执行乘法运算的最大分数") | [Go](problems/maximum-score-from-performing-multiplication-operations) | Medium |
75+
| <span id="1769">1769</span> | [Minimum Number of Operations to Move All Balls to Each Box](https://leetcode.com/problems/minimum-number-of-operations-to-move-all-balls-to-each-box "移动所有球到每个盒子所需的最小操作数") | [Go](problems/minimum-number-of-operations-to-move-all-balls-to-each-box) | Medium |
76+
| <span id="1768">1768</span> | [Merge Strings Alternately](https://leetcode.com/problems/merge-strings-alternately "交替合并字符串") | [Go](problems/merge-strings-alternately) | Easy |
77+
| <span id="1767">1767</span> | [Find the Subtasks That Did Not Execute](https://leetcode.com/problems/find-the-subtasks-that-did-not-execute) 🔒 | [MySQL](problems/find-the-subtasks-that-did-not-execute) | Hard |
78+
| <span id="1766">1766</span> | [Tree of Coprimes](https://leetcode.com/problems/tree-of-coprimes "互质树") | [Go](problems/tree-of-coprimes) | Hard |
79+
| <span id="1765">1765</span> | [Map of Highest Peak](https://leetcode.com/problems/map-of-highest-peak "地图中的最高点") | [Go](problems/map-of-highest-peak) | Medium |
80+
| <span id="1764">1764</span> | [Form Array by Concatenating Subarrays of Another Array](https://leetcode.com/problems/form-array-by-concatenating-subarrays-of-another-array "通过连接另一个数组的子数组得到一个数组") | [Go](problems/form-array-by-concatenating-subarrays-of-another-array) | Medium |
81+
| <span id="1763">1763</span> | [Longest Nice Substring](https://leetcode.com/problems/longest-nice-substring "最长的美好子字符串") | [Go](problems/longest-nice-substring) | Easy |
82+
| <span id="1762">1762</span> | [Buildings With an Ocean View](https://leetcode.com/problems/buildings-with-an-ocean-view) 🔒 | [Go](problems/buildings-with-an-ocean-view) | Medium |
83+
| <span id="1761">1761</span> | [Minimum Degree of a Connected Trio in a Graph](https://leetcode.com/problems/minimum-degree-of-a-connected-trio-in-a-graph "一个图中连通三元组的最小度数") | [Go](problems/minimum-degree-of-a-connected-trio-in-a-graph) | Hard |
84+
| <span id="1760">1760</span> | [Minimum Limit of Balls in a Bag](https://leetcode.com/problems/minimum-limit-of-balls-in-a-bag "袋子里最少数目的球") | [Go](problems/minimum-limit-of-balls-in-a-bag) | Medium |
85+
| <span id="1759">1759</span> | [Count Number of Homogenous Substrings](https://leetcode.com/problems/count-number-of-homogenous-substrings "统计同构子字符串的数目") | [Go](problems/count-number-of-homogenous-substrings) | Medium |
86+
| <span id="1758">1758</span> | [Minimum Changes To Make Alternating Binary String](https://leetcode.com/problems/minimum-changes-to-make-alternating-binary-string "生成交替二进制字符串的最少操作数") | [Go](problems/minimum-changes-to-make-alternating-binary-string) | Easy |
87+
| <span id="1757">1757</span> | [Recyclable and Low Fat Products](https://leetcode.com/problems/recyclable-and-low-fat-products) 🔒 | [MySQL](problems/recyclable-and-low-fat-products) | Easy |
88+
| <span id="1756">1756</span> | [Design Most Recently Used Queue](https://leetcode.com/problems/design-most-recently-used-queue) 🔒 | [Go](problems/design-most-recently-used-queue) | Medium |
89+
| <span id="1755">1755</span> | [Closest Subsequence Sum](https://leetcode.com/problems/closest-subsequence-sum "最接近目标值的子序列和") | [Go](problems/closest-subsequence-sum) | Hard |
90+
| <span id="1754">1754</span> | [Largest Merge Of Two Strings](https://leetcode.com/problems/largest-merge-of-two-strings "构造字典序最大的合并字符串") | [Go](problems/largest-merge-of-two-strings) | Medium |
91+
| <span id="1753">1753</span> | [Maximum Score From Removing Stones](https://leetcode.com/problems/maximum-score-from-removing-stones "移除石子的最大得分") | [Go](problems/maximum-score-from-removing-stones) | Medium |
92+
| <span id="1752">1752</span> | [Check if Array Is Sorted and Rotated](https://leetcode.com/problems/check-if-array-is-sorted-and-rotated "检查数组是否经排序和轮转得到") | [Go](problems/check-if-array-is-sorted-and-rotated) | Easy |
93+
| <span id="1751">1751</span> | [Maximum Number of Events That Can Be Attended II](https://leetcode.com/problems/maximum-number-of-events-that-can-be-attended-ii "最多可以参加的会议数目 II") | [Go](problems/maximum-number-of-events-that-can-be-attended-ii) | Hard |
94+
| <span id="1750">1750</span> | [Minimum Length of String After Deleting Similar Ends](https://leetcode.com/problems/minimum-length-of-string-after-deleting-similar-ends "删除字符串两端相同字符后的最短长度") | [Go](problems/minimum-length-of-string-after-deleting-similar-ends) | Medium |
95+
| <span id="1749">1749</span> | [Maximum Absolute Sum of Any Subarray](https://leetcode.com/problems/maximum-absolute-sum-of-any-subarray "任意子数组和的绝对值的最大值") | [Go](problems/maximum-absolute-sum-of-any-subarray) | Medium |
96+
| <span id="1748">1748</span> | [Sum of Unique Elements](https://leetcode.com/problems/sum-of-unique-elements "唯一元素的和") | [Go](problems/sum-of-unique-elements) | Easy |
7397
| <span id="1747">1747</span> | [Leetflex Banned Accounts](https://leetcode.com/problems/leetflex-banned-accounts) 🔒 | [MySQL](problems/leetflex-banned-accounts) | Medium |
7498
| <span id="1746">1746</span> | [Maximum Subarray Sum After One Operation](https://leetcode.com/problems/maximum-subarray-sum-after-one-operation) 🔒 | [Go](problems/maximum-subarray-sum-after-one-operation) | Medium |
7599
| <span id="1745">1745</span> | [Palindrome Partitioning IV](https://leetcode.com/problems/palindrome-partitioning-iv "回文串分割 IV") | [Go](problems/palindrome-partitioning-iv) | Hard |

problems/best-sightseeing-pair/README.md

+18-13
Original file line numberDiff line numberDiff line change
@@ -11,30 +11,35 @@
1111

1212
## [1014. Best Sightseeing Pair (Medium)](https://leetcode.com/problems/best-sightseeing-pair "最佳观光组合")
1313

14-
<p>Given an array <code>A</code> of positive integers, <code>A[i]</code> represents the value of the <code>i</code>-th sightseeing spot, and two&nbsp;sightseeing spots <code>i</code> and <code>j</code>&nbsp;have distance <code>j - i</code>&nbsp;between them.</p>
14+
<p>You are given an integer array <code>values</code> where values[i] represents the value of the <code>i<sup>th</sup></code> sightseeing spot. Two sightseeing spots <code>i</code> and <code>j</code> have a <strong>distance</strong> <code>j - i</code> between them.</p>
1515

16-
<p>The <em>score</em>&nbsp;of a pair (<code>i &lt; j</code>) of sightseeing spots is (<code>A[i] + A[j] + i&nbsp;- j)</code> : the sum of the values of the sightseeing spots, <strong>minus</strong> the distance between them.</p>
16+
<p>The score of a pair (<code>i &lt; j</code>) of sightseeing spots is <code>values[i] + values[j] + i - j</code>: the sum of the values of the sightseeing spots, minus the distance between them.</p>
1717

18-
<p>Return the maximum score of a pair of sightseeing spots.</p>
18+
<p>Return <em>the maximum score of a pair of sightseeing spots</em>.</p>
1919

2020
<p>&nbsp;</p>
21-
2221
<p><strong>Example 1:</strong></p>
2322

2423
<pre>
25-
<strong>Input: </strong><span id="example-input-1-1">[8,1,5,2,6]</span>
26-
<strong>Output: </strong><span id="example-output-1">11
27-
<strong>Explanation:</strong> i = 0, j = 2, </span><code>A[i] + A[j] + i - j = 8 + 5 + 0 - 2 = 11</code>
24+
<strong>Input:</strong> values = [8,1,5,2,6]
25+
<strong>Output:</strong> 11
26+
<strong>Explanation:</strong> i = 0, j = 2, values[i] + values[j] + i - j = 8 + 5 + 0 - 2 = 11
2827
</pre>
2928

30-
<p>&nbsp;</p>
29+
<p><strong>Example 2:</strong></p>
30+
31+
<pre>
32+
<strong>Input:</strong> values = [1,2]
33+
<strong>Output:</strong> 2
34+
</pre>
3135

32-
<p><strong>Note:</strong></p>
36+
<p>&nbsp;</p>
37+
<p><strong>Constraints:</strong></p>
3338

34-
<ol>
35-
<li><code>2 &lt;= A.length &lt;= 50000</code></li>
36-
<li><code>1 &lt;= A[i] &lt;= 1000</code></li>
37-
</ol>
39+
<ul>
40+
<li><code>2 &lt;= values.length &lt;= 5 * 10<sup>4</sup></code></li>
41+
<li><code>1 &lt;= values[i] &lt;= 1000</code></li>
42+
</ul>
3843

3944
### Related Topics
4045
[[Array](../../tag/array/README.md)]

problems/best-time-to-buy-and-sell-stock-ii/README.md

+13-12
Original file line numberDiff line numberDiff line change
@@ -11,44 +11,45 @@
1111

1212
## [122. Best Time to Buy and Sell Stock II (Easy)](https://leetcode.com/problems/best-time-to-buy-and-sell-stock-ii "买卖股票的最佳时机 II")
1313

14-
<p>Say you have an array <code>prices</code> for which the <em>i</em><sup>th</sup> element is the price of a given stock on day <em>i</em>.</p>
14+
<p>You are given an array <code>prices</code> for which the <code>i<sup>th</sup></code> element is the price of a given stock on day <code>i</code>.</p>
1515

16-
<p>Design an algorithm to find the maximum profit. You may complete as many transactions as you like (i.e., buy one and sell one share of the stock multiple times).</p>
16+
<p>Find the maximum profit you can achieve. You may complete as many transactions as you like (i.e., buy one and sell one share of the stock multiple times).</p>
1717

18-
<p><strong>Note:</strong> You may not engage in multiple transactions at the same time (i.e., you must sell the stock before you buy again).</p>
18+
<p><strong>Note:</strong> You may not engage in multiple transactions simultaneously (i.e., you must sell the stock before you buy again).</p>
1919

20+
<p>&nbsp;</p>
2021
<p><strong>Example 1:</strong></p>
2122

2223
<pre>
23-
<strong>Input:</strong> [7,1,5,3,6,4]
24+
<strong>Input:</strong> prices = [7,1,5,3,6,4]
2425
<strong>Output:</strong> 7
2526
<strong>Explanation:</strong> Buy on day 2 (price = 1) and sell on day 3 (price = 5), profit = 5-1 = 4.
26-
&nbsp; Then buy on day 4 (price = 3) and sell on day 5 (price = 6), profit = 6-3 = 3.
27+
Then buy on day 4 (price = 3) and sell on day 5 (price = 6), profit = 6-3 = 3.
2728
</pre>
2829

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

3132
<pre>
32-
<strong>Input:</strong> [1,2,3,4,5]
33+
<strong>Input:</strong> prices = [1,2,3,4,5]
3334
<strong>Output:</strong> 4
3435
<strong>Explanation:</strong> Buy on day 1 (price = 1) and sell on day 5 (price = 5), profit = 5-1 = 4.
35-
&nbsp; Note that you cannot buy on day 1, buy on day 2 and sell them later, as you are
36-
&nbsp; engaging multiple transactions at the same time. You must sell before buying again.
36+
Note that you cannot buy on day 1, buy on day 2 and sell them later, as you are engaging multiple transactions at the same time. You must sell before buying again.
3737
</pre>
3838

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

4141
<pre>
42-
<strong>Input:</strong> [7,6,4,3,1]
42+
<strong>Input:</strong> prices = [7,6,4,3,1]
4343
<strong>Output:</strong> 0
44-
<strong>Explanation:</strong> In this case, no transaction is done, i.e. max profit = 0.</pre>
44+
<strong>Explanation:</strong> In this case, no transaction is done, i.e., max profit = 0.
45+
</pre>
4546

4647
<p>&nbsp;</p>
4748
<p><strong>Constraints:</strong></p>
4849

4950
<ul>
50-
<li><code>1 &lt;= prices.length &lt;= 3 * 10 ^ 4</code></li>
51-
<li><code>0 &lt;= prices[i]&nbsp;&lt;= 10 ^ 4</code></li>
51+
<li><code>1 &lt;= prices.length &lt;= 3 * 10<sup>4</sup></code></li>
52+
<li><code>0 &lt;= prices[i] &lt;= 10<sup>4</sup></code></li>
5253
</ul>
5354

5455
### Related Topics

problems/binary-tree-level-order-traversal-ii/README.md

+27-19
Original file line numberDiff line numberDiff line change
@@ -9,31 +9,39 @@
99

1010
[Next >](../convert-sorted-array-to-binary-search-tree "Convert Sorted Array to Binary Search Tree")
1111

12-
## [107. Binary Tree Level Order Traversal II (Easy)](https://leetcode.com/problems/binary-tree-level-order-traversal-ii "二叉树的层序遍历 II")
12+
## [107. Binary Tree Level Order Traversal II (Medium)](https://leetcode.com/problems/binary-tree-level-order-traversal-ii "二叉树的层序遍历 II")
1313

14-
<p>Given a binary tree, return the <i>bottom-up level order</i> traversal of its nodes' values. (ie, from left to right, level by level from leaf to root).</p>
14+
<p>Given the <code>root</code> of a binary tree, return <em>the bottom-up level order traversal of its nodes&#39; values</em>. (i.e., from left to right, level by level from leaf to root).</p>
1515

16-
<p>
17-
For example:<br />
18-
Given binary tree <code>[3,9,20,null,null,15,7]</code>,<br />
16+
<p>&nbsp;</p>
17+
<p><strong>Example 1:</strong></p>
18+
<img alt="" src="https://assets.leetcode.com/uploads/2021/02/19/tree1.jpg" style="width: 277px; height: 302px;" />
1919
<pre>
20-
3
21-
/ \
22-
9 20
23-
/ \
24-
15 7
20+
<strong>Input:</strong> root = [3,9,20,null,null,15,7]
21+
<strong>Output:</strong> [[15,7],[9,20],[3]]
2522
</pre>
26-
</p>
27-
<p>
28-
return its bottom-up level order traversal as:<br />
23+
24+
<p><strong>Example 2:</strong></p>
25+
26+
<pre>
27+
<strong>Input:</strong> root = [1]
28+
<strong>Output:</strong> [[1]]
29+
</pre>
30+
31+
<p><strong>Example 3:</strong></p>
32+
2933
<pre>
30-
[
31-
[15,7],
32-
[9,20],
33-
[3]
34-
]
34+
<strong>Input:</strong> root = []
35+
<strong>Output:</strong> []
3536
</pre>
36-
</p>
37+
38+
<p>&nbsp;</p>
39+
<p><strong>Constraints:</strong></p>
40+
41+
<ul>
42+
<li>The number of nodes in the tree is in the range <code>[0, 2000]</code>.</li>
43+
<li><code>-1000 &lt;= Node.val &lt;= 1000</code></li>
44+
</ul>
3745

3846
### Related Topics
3947
[[Tree](../../tag/tree/README.md)]

problems/binary-tree-level-order-traversal/README.md

+27-19
Original file line numberDiff line numberDiff line change
@@ -11,37 +11,45 @@
1111

1212
## [102. Binary Tree Level Order Traversal (Medium)](https://leetcode.com/problems/binary-tree-level-order-traversal "二叉树的层序遍历")
1313

14-
<p>Given a binary tree, return the <i>level order</i> traversal of its nodes' values. (ie, from left to right, level by level).</p>
14+
<p>Given the <code>root</code> of a binary tree, return <em>the level order traversal of its nodes&#39; values</em>. (i.e., from left to right, level by level).</p>
1515

16-
<p>
17-
For example:<br />
18-
Given binary tree <code>[3,9,20,null,null,15,7]</code>,<br />
16+
<p>&nbsp;</p>
17+
<p><strong>Example 1:</strong></p>
18+
<img alt="" src="https://assets.leetcode.com/uploads/2021/02/19/tree1.jpg" style="width: 277px; height: 302px;" />
1919
<pre>
20-
3
21-
/ \
22-
9 20
23-
/ \
24-
15 7
20+
<strong>Input:</strong> root = [3,9,20,null,null,15,7]
21+
<strong>Output:</strong> [[3],[9,20],[15,7]]
2522
</pre>
26-
</p>
27-
<p>
28-
return its level order traversal as:<br />
23+
24+
<p><strong>Example 2:</strong></p>
25+
26+
<pre>
27+
<strong>Input:</strong> root = [1]
28+
<strong>Output:</strong> [[1]]
29+
</pre>
30+
31+
<p><strong>Example 3:</strong></p>
32+
2933
<pre>
30-
[
31-
[3],
32-
[9,20],
33-
[15,7]
34-
]
34+
<strong>Input:</strong> root = []
35+
<strong>Output:</strong> []
3536
</pre>
36-
</p>
37+
38+
<p>&nbsp;</p>
39+
<p><strong>Constraints:</strong></p>
40+
41+
<ul>
42+
<li>The number of nodes in the tree is in the range <code>[0, 2000]</code>.</li>
43+
<li><code>-1000 &lt;= Node.val &lt;= 1000</code></li>
44+
</ul>
3745

3846
### Related Topics
3947
[[Tree](../../tag/tree/README.md)]
4048
[[Breadth-first Search](../../tag/breadth-first-search/README.md)]
4149

4250
### Similar Questions
4351
1. [Binary Tree Zigzag Level Order Traversal](../binary-tree-zigzag-level-order-traversal) (Medium)
44-
1. [Binary Tree Level Order Traversal II](../binary-tree-level-order-traversal-ii) (Easy)
52+
1. [Binary Tree Level Order Traversal II](../binary-tree-level-order-traversal-ii) (Medium)
4553
1. [Minimum Depth of Binary Tree](../minimum-depth-of-binary-tree) (Easy)
4654
1. [Binary Tree Vertical Order Traversal](../binary-tree-vertical-order-traversal) (Medium)
4755
1. [Average of Levels in Binary Tree](../average-of-levels-in-binary-tree) (Easy)

problems/binary-tree-right-side-view/README.md

+29-11
Original file line numberDiff line numberDiff line change
@@ -11,26 +11,44 @@
1111

1212
## [199. Binary Tree Right Side View (Medium)](https://leetcode.com/problems/binary-tree-right-side-view "二叉树的右视图")
1313

14-
<p>Given a binary tree, imagine yourself standing on the <em>right</em> side of it, return the values of the nodes you can see ordered from top to bottom.</p>
14+
<p>Given the <code>root</code> of a binary tree, imagine yourself standing on the <strong>right side</strong> of it, return <em>the values of the nodes you can see ordered from top to bottom</em>.</p>
1515

16-
<p><strong>Example:</strong></p>
16+
<p>&nbsp;</p>
17+
<p><strong>Example 1:</strong></p>
18+
<img alt="" src="https://assets.leetcode.com/uploads/2021/02/14/tree.jpg" style="width: 401px; height: 301px;" />
19+
<pre>
20+
<strong>Input:</strong> root = [1,2,3,null,5,null,4]
21+
<strong>Output:</strong> [1,3,4]
22+
</pre>
23+
24+
<p><strong>Example 2:</strong></p>
1725

1826
<pre>
19-
<strong>Input:</strong>&nbsp;[1,2,3,null,5,null,4]
20-
<strong>Output:</strong>&nbsp;[1, 3, 4]
21-
<strong>Explanation:
22-
</strong>
23-
1 &lt;---
24-
/ \
25-
2 3 &lt;---
26-
\ \
27-
5 4 &lt;---
27+
<strong>Input:</strong> root = [1,null,3]
28+
<strong>Output:</strong> [1,3]
2829
</pre>
2930

31+
<p><strong>Example 3:</strong></p>
32+
33+
<pre>
34+
<strong>Input:</strong> root = []
35+
<strong>Output:</strong> []
36+
</pre>
37+
38+
<p>&nbsp;</p>
39+
<p><strong>Constraints:</strong></p>
40+
41+
<ul>
42+
<li>The number of nodes in the tree is in the range <code>[0, 100]</code>.</li>
43+
<li><code>-100 &lt;= Node.val &lt;= 100</code></li>
44+
</ul>
45+
3046
### Related Topics
3147
[[Tree](../../tag/tree/README.md)]
3248
[[Depth-first Search](../../tag/depth-first-search/README.md)]
3349
[[Breadth-first Search](../../tag/breadth-first-search/README.md)]
50+
[[Recursion](../../tag/recursion/README.md)]
51+
[[Queue](../../tag/queue/README.md)]
3452

3553
### Similar Questions
3654
1. [Populating Next Right Pointers in Each Node](../populating-next-right-pointers-in-each-node) (Medium)

problems/binary-tree-zigzag-level-order-traversal/README.md

+26-18
Original file line numberDiff line numberDiff line change
@@ -11,29 +11,37 @@
1111

1212
## [103. Binary Tree Zigzag Level Order Traversal (Medium)](https://leetcode.com/problems/binary-tree-zigzag-level-order-traversal "二叉树的锯齿形层序遍历")
1313

14-
<p>Given a binary tree, return the <i>zigzag level order</i> traversal of its nodes' values. (ie, from left to right, then right to left for the next level and alternate between).</p>
14+
<p>Given the <code>root</code> of a binary tree, return <em>the zigzag level order traversal of its nodes&#39; values</em>. (i.e., from left to right, then right to left for the next level and alternate between).</p>
1515

16-
<p>
17-
For example:<br />
18-
Given binary tree <code>[3,9,20,null,null,15,7]</code>,<br />
16+
<p>&nbsp;</p>
17+
<p><strong>Example 1:</strong></p>
18+
<img alt="" src="https://assets.leetcode.com/uploads/2021/02/19/tree1.jpg" style="width: 277px; height: 302px;" />
1919
<pre>
20-
3
21-
/ \
22-
9 20
23-
/ \
24-
15 7
20+
<strong>Input:</strong> root = [3,9,20,null,null,15,7]
21+
<strong>Output:</strong> [[3],[20,9],[15,7]]
2522
</pre>
26-
</p>
27-
<p>
28-
return its zigzag level order traversal as:<br />
23+
24+
<p><strong>Example 2:</strong></p>
25+
26+
<pre>
27+
<strong>Input:</strong> root = [1]
28+
<strong>Output:</strong> [[1]]
29+
</pre>
30+
31+
<p><strong>Example 3:</strong></p>
32+
2933
<pre>
30-
[
31-
[3],
32-
[20,9],
33-
[15,7]
34-
]
34+
<strong>Input:</strong> root = []
35+
<strong>Output:</strong> []
3536
</pre>
36-
</p>
37+
38+
<p>&nbsp;</p>
39+
<p><strong>Constraints:</strong></p>
40+
41+
<ul>
42+
<li>The number of nodes in the tree is in the range <code>[0, 2000]</code>.</li>
43+
<li><code>-100 &lt;= Node.val &lt;= 100</code></li>
44+
</ul>
3745

3846
### Related Topics
3947
[[Stack](../../tag/stack/README.md)]

0 commit comments

Comments
 (0)