Skip to content

Commit e1da124

Browse files
author
Shuo
committed
A: new
1 parent b45e5b4 commit e1da124

File tree

49 files changed

+1091
-327
lines changed

Some content is hidden

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

49 files changed

+1091
-327
lines changed

README.md

+11-1
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,16 @@ LeetCode Problems' Solutions
7070

7171
| # | Title | Solution | Difficulty |
7272
| :-: | - | - | :-: |
73+
| <span id="1691">1691</span> | [Maximum Height by Stacking Cuboids](https://leetcode.com/problems/maximum-height-by-stacking-cuboids "堆叠长方体的最大高度") | [Go](problems/maximum-height-by-stacking-cuboids) | Hard |
74+
| <span id="1690">1690</span> | [Stone Game VII](https://leetcode.com/problems/stone-game-vii "石子游戏 VII") | [Go](problems/stone-game-vii) | Medium |
75+
| <span id="1689">1689</span> | [Partitioning Into Minimum Number Of Deci-Binary Numbers](https://leetcode.com/problems/partitioning-into-minimum-number-of-deci-binary-numbers "十-二进制数的最少数目") | [Go](problems/partitioning-into-minimum-number-of-deci-binary-numbers) | Medium |
76+
| <span id="1688">1688</span> | [Count of Matches in Tournament](https://leetcode.com/problems/count-of-matches-in-tournament "比赛中的配对次数") | [Go](problems/count-of-matches-in-tournament) | Easy |
77+
| <span id="1687">1687</span> | [Delivering Boxes from Storage to Ports](https://leetcode.com/problems/delivering-boxes-from-storage-to-ports "从仓库到码头运输箱子") | [Go](problems/delivering-boxes-from-storage-to-ports) | Hard |
78+
| <span id="1686">1686</span> | [Stone Game VI](https://leetcode.com/problems/stone-game-vi "石子游戏 VI") | [Go](problems/stone-game-vi) | Medium |
79+
| <span id="1685">1685</span> | [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 |
80+
| <span id="1684">1684</span> | [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 |
81+
| <span id="1683">1683</span> | [Invalid Tweets](https://leetcode.com/problems/invalid-tweets) 🔒 | [MySQL](problems/invalid-tweets) | Easy |
82+
| <span id="1682">1682</span> | [Longest Palindromic Subsequence II](https://leetcode.com/problems/longest-palindromic-subsequence-ii) 🔒 | [Go](problems/longest-palindromic-subsequence-ii) | Medium |
7383
| <span id="1681">1681</span> | [Minimum Incompatibility](https://leetcode.com/problems/minimum-incompatibility "最小不兼容性") | [Go](problems/minimum-incompatibility) | Hard |
7484
| <span id="1680">1680</span> | [Concatenation of Consecutive Binary Numbers](https://leetcode.com/problems/concatenation-of-consecutive-binary-numbers "连接连续二进制数字") | [Go](problems/concatenation-of-consecutive-binary-numbers) | Medium |
7585
| <span id="1679">1679</span> | [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 |
@@ -85,7 +95,7 @@ LeetCode Problems' Solutions
8595
| <span id="1669">1669</span> | [Merge In Between Linked Lists](https://leetcode.com/problems/merge-in-between-linked-lists "合并两个链表") | [Go](problems/merge-in-between-linked-lists) | Medium |
8696
| <span id="1668">1668</span> | [Maximum Repeating Substring](https://leetcode.com/problems/maximum-repeating-substring "最大重复子字符串") | [Go](problems/maximum-repeating-substring) | Easy |
8797
| <span id="1667">1667</span> | [Fix Names in a Table](https://leetcode.com/problems/fix-names-in-a-table) 🔒 | [MySQL](problems/fix-names-in-a-table) | Easy |
88-
| <span id="1666">1666</span> | [Change the Root of a Binary Tree](https://leetcode.com/problems/change-the-root-of-a-binary-tree) 🔒 | [Go](problems/change-the-root-of-a-binary-tree) | Medium |
98+
| <span id="1666">1666</span> | [Change the Root of a Binary Tree](https://leetcode.com/problems/change-the-root-of-a-binary-tree "改变二叉树的根节点") 🔒 | [Go](problems/change-the-root-of-a-binary-tree) | Medium |
8999
| <span id="1665">1665</span> | [Minimum Initial Energy to Finish Tasks](https://leetcode.com/problems/minimum-initial-energy-to-finish-tasks "完成所有任务的最少初始能量") | [Go](problems/minimum-initial-energy-to-finish-tasks) | Hard |
90100
| <span id="1664">1664</span> | [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 |
91101
| <span id="1663">1663</span> | [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 |

problems/binary-trees-with-factors/README.md

+12-14
Original file line numberDiff line numberDiff line change
@@ -11,33 +11,31 @@
1111

1212
## [823. Binary Trees With Factors (Medium)](https://leetcode.com/problems/binary-trees-with-factors "带因子的二叉树")
1313

14-
<p>Given an array of unique integers, each integer is strictly greater than 1.</p>
14+
<p>Given an array of unique integers, <code>arr</code>, where each integer <code>arr[i]</code> is strictly greater than <code>1</code>.</p>
1515

16-
<p>We make a binary tree using these integers&nbsp;and each number may be used for any number of times.</p>
16+
<p>We make a binary tree using these integers, and each number may be used for any number of times. Each non-leaf node&#39;s value should be equal to the product of the values of its children.</p>
1717

18-
<p>Each non-leaf node&#39;s&nbsp;value should be equal to the product of the values of it&#39;s children.</p>
19-
20-
<p>How many binary trees can we make?&nbsp; Return the answer <strong>modulo 10 ** 9 + 7</strong>.</p>
18+
<p>Return <em>the number of binary trees we can make</em>. The answer may be too large so return the answer <strong>modulo</strong> <code>10<sup>9</sup> + 7</code>.</p>
2119

20+
<p>&nbsp;</p>
2221
<p><strong>Example 1:</strong></p>
2322

2423
<pre>
25-
<strong>Input:</strong> <code>A = [2, 4]</code>
24+
<strong>Input:</strong> arr = [2,4]
2625
<strong>Output:</strong> 3
2726
<strong>Explanation:</strong> We can make these trees: <code>[2], [4], [4, 2, 2]</code></pre>
2827

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

3130
<pre>
32-
<strong>Input:</strong> <code>A = [2, 4, 5, 10]</code>
33-
<strong>Output:</strong> <code>7</code>
31+
<strong>Input:</strong> arr = [2,4,5,10]
32+
<strong>Output:</strong> 7
3433
<strong>Explanation:</strong> We can make these trees: <code>[2], [4], [5], [10], [4, 2, 2], [10, 2, 5], [10, 5, 2]</code>.</pre>
3534

3635
<p>&nbsp;</p>
36+
<p><strong>Constraints:</strong></p>
3737

38-
<p><strong>Note:</strong></p>
39-
40-
<ol>
41-
<li><code>1 &lt;= A.length &lt;=&nbsp;1000</code>.</li>
42-
<li><code>2 &lt;=&nbsp;A[i]&nbsp;&lt;=&nbsp;10 ^ 9</code>.</li>
43-
</ol>
38+
<ul>
39+
<li><code>1 &lt;= arr.length &lt;= 1000</code></li>
40+
<li><code>2 &lt;= arr[i] &lt;= 10<sup>9</sup></code></li>
41+
</ul>

problems/build-an-array-with-stack-operations/README.md

+2-6
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,7 @@
2121
<li>If the target array is already&nbsp;built, stop reading more elements.</li>
2222
</ul>
2323

24-
<p>You are guaranteed that the target array is strictly&nbsp;increasing, only containing&nbsp;numbers between 1 to <code>n</code>&nbsp;inclusive.</p>
25-
26-
<p>Return the operations to build the target array.</p>
27-
28-
<p>You are guaranteed that the answer is unique.</p>
24+
<p>Return the operations to build the target array. You are guaranteed that the answer is unique.</p>
2925

3026
<p>&nbsp;</p>
3127
<p><strong>Example 1:</strong></p>
@@ -66,7 +62,7 @@ Read number 3 and automatically push in the array -&gt; [1,3]
6662

6763
<ul>
6864
<li><code>1 &lt;= target.length &lt;= 100</code></li>
69-
<li><code>1 &lt;= target[i]&nbsp;&lt;= 100</code></li>
65+
<li><code>1 &lt;= target[i]&nbsp;&lt;= n</code></li>
7066
<li><code>1 &lt;= n &lt;= 100</code></li>
7167
<li><code>target</code> is strictly&nbsp;increasing.</li>
7268
</ul>

problems/change-the-root-of-a-binary-tree/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
[Next >](../fix-names-in-a-table "Fix Names in a Table")
1111

12-
## [1666. Change the Root of a Binary Tree (Medium)](https://leetcode.com/problems/change-the-root-of-a-binary-tree "")
12+
## [1666. Change the Root of a Binary Tree (Medium)](https://leetcode.com/problems/change-the-root-of-a-binary-tree "改变二叉树的根节点")
1313

1414

1515

problems/constrained-subsequence-sum/README.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111

1212
## [1425. Constrained Subsequence Sum (Hard)](https://leetcode.com/problems/constrained-subsequence-sum "带限制的子序列和")
1313

14-
<p>Given an integer array&nbsp;<code>nums</code>&nbsp;and an integer <code>k</code>, return the maximum sum of a <strong>non-empty</strong> subsequence&nbsp;of that array such that for every&nbsp;two <strong>consecutive</strong> integers in the subsequence,&nbsp;<code>nums[i]</code>&nbsp;and&nbsp;<code>nums[j]</code>, where&nbsp;<code>i &lt; j</code>, the condition&nbsp;<code>j - i &lt;= k</code>&nbsp;is satisfied.</p>
14+
<p>Given an integer array <code>nums</code> and an integer <code>k</code>, return the maximum sum of a <strong>non-empty</strong> subsequence of that array such that for every two <strong>consecutive</strong> integers in the subsequence, <code>nums[i]</code> and <code>nums[j]</code>, where <code>i &lt; j</code>, the condition <code>j - i &lt;= k</code> is satisfied.</p>
1515

16-
<p>A&nbsp;<em>subsequence</em>&nbsp;of an array is&nbsp;obtained by deleting some number of elements (can be&nbsp;zero) from the array, leaving the remaining elements in their original order.</p>
16+
<p>A <em>subsequence</em> of an array is obtained by deleting some number of elements (can be zero) from the array, leaving the remaining elements in their original order.</p>
1717

1818
<p>&nbsp;</p>
1919
<p><strong>Example 1:</strong></p>
@@ -44,8 +44,8 @@
4444
<p><strong>Constraints:</strong></p>
4545

4646
<ul>
47-
<li><code>1 &lt;= k &lt;= nums.length &lt;= 10^5</code></li>
48-
<li><code>-10^4&nbsp;&lt;= nums[i] &lt;= 10^4</code></li>
47+
<li><code>1 &lt;= k &lt;= nums.length &lt;= 10<sup>5</sup></code></li>
48+
<li><code>-10<sup>4</sup> &lt;= nums[i] &lt;= 10<sup>4</sup></code></li>
4949
</ul>
5050

5151
### Related Topics
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
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](../delivering-boxes-from-storage-to-ports "Delivering Boxes from Storage to Ports")
9+
                
10+
[Next >](../partitioning-into-minimum-number-of-deci-binary-numbers "Partitioning Into Minimum Number Of Deci-Binary Numbers")
11+
12+
## [1688. Count of Matches in Tournament (Easy)](https://leetcode.com/problems/count-of-matches-in-tournament "比赛中的配对次数")
13+
14+
<p>You are given an integer <code>n</code>, the number of teams in a tournament that has strange rules:</p>
15+
16+
<ul>
17+
<li>If the current number of teams is <strong>even</strong>, each team gets paired with another team. A total of <code>n / 2</code> matches are played, and <code>n / 2</code> teams advance to the next round.</li>
18+
<li>If the current number of teams is <strong>odd</strong>, one team randomly advances in the tournament, and the rest gets paired. A total of <code>(n - 1) / 2</code> matches are played, and <code>(n - 1) / 2 + 1</code> teams advance to the next round.</li>
19+
</ul>
20+
21+
<p>Return <em>the number of matches played in the tournament until a winner is decided.</em></p>
22+
23+
<p>&nbsp;</p>
24+
<p><strong>Example 1:</strong></p>
25+
26+
<pre>
27+
<strong>Input:</strong> n = 7
28+
<strong>Output:</strong> 6
29+
<strong>Explanation:</strong> Details of the tournament:
30+
- 1st Round: Teams = 7, Matches = 3, and 4 teams advance.
31+
- 2nd Round: Teams = 4, Matches = 2, and 2 teams advance.
32+
- 3rd Round: Teams = 2, Matches = 1, and 1 team is declared the winner.
33+
Total number of matches = 3 + 2 + 1 = 6.
34+
</pre>
35+
36+
<p><strong>Example 2:</strong></p>
37+
38+
<pre>
39+
<strong>Input:</strong> n = 14
40+
<strong>Output:</strong> 13
41+
<strong>Explanation:</strong> Details of the tournament:
42+
- 1st Round: Teams = 14, Matches = 7, and 7 teams advance.
43+
- 2nd Round: Teams = 7, Matches = 3, and 4 teams advance.
44+
- 3rd Round: Teams = 4, Matches = 2, and 2 teams advance.
45+
- 4th Round: Teams = 2, Matches = 1, and 1 team is declared the winner.
46+
Total number of matches = 7 + 3 + 2 + 1 = 13.
47+
</pre>
48+
49+
<p>&nbsp;</p>
50+
<p><strong>Constraints:</strong></p>
51+
52+
<ul>
53+
<li><code>1 &lt;= n &lt;= 200</code></li>
54+
</ul>
55+
56+
### Related Topics
57+
[[Backtracking](../../tag/backtracking/README.md)]
58+
59+
### Hints
60+
<details>
61+
<summary>Hint 1</summary>
62+
Simulate the tournament as given in the statement.
63+
</details>
64+
65+
<details>
66+
<summary>Hint 2</summary>
67+
Be careful when handling odd integers.
68+
</details>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
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](../invalid-tweets "Invalid Tweets")
9+
                
10+
[Next >](../sum-of-absolute-differences-in-a-sorted-array "Sum of Absolute Differences in a Sorted Array")
11+
12+
## [1684. Count the Number of Consistent Strings (Easy)](https://leetcode.com/problems/count-the-number-of-consistent-strings "统计一致字符串的数目")
13+
14+
<p>You are given a string <code>allowed</code> consisting of <strong>distinct</strong> characters and an array of strings <code>words</code>. A string is <strong>consistent </strong>if all characters in the string appear in the string <code>allowed</code>.</p>
15+
16+
<p>Return<em> the number of <strong>consistent</strong> strings in the array </em><code>words</code>.</p>
17+
18+
<p>&nbsp;</p>
19+
<p><strong>Example 1:</strong></p>
20+
21+
<pre>
22+
<strong>Input:</strong> allowed = &quot;ab&quot;, words = [&quot;ad&quot;,&quot;bd&quot;,&quot;aaab&quot;,&quot;baa&quot;,&quot;badab&quot;]
23+
<strong>Output:</strong> 2
24+
<strong>Explanation:</strong> Strings &quot;aaab&quot; and &quot;baa&quot; are consistent since they only contain characters &#39;a&#39; and &#39;b&#39;.
25+
</pre>
26+
27+
<p><strong>Example 2:</strong></p>
28+
29+
<pre>
30+
<strong>Input:</strong> allowed = &quot;abc&quot;, words = [&quot;a&quot;,&quot;b&quot;,&quot;c&quot;,&quot;ab&quot;,&quot;ac&quot;,&quot;bc&quot;,&quot;abc&quot;]
31+
<strong>Output:</strong> 7
32+
<strong>Explanation:</strong> All strings are consistent.
33+
</pre>
34+
35+
<p><strong>Example 3:</strong></p>
36+
37+
<pre>
38+
<strong>Input:</strong> allowed = &quot;cad&quot;, words = [&quot;cc&quot;,&quot;acd&quot;,&quot;b&quot;,&quot;ba&quot;,&quot;bac&quot;,&quot;bad&quot;,&quot;ac&quot;,&quot;d&quot;]
39+
<strong>Output:</strong> 4
40+
<strong>Explanation:</strong> Strings &quot;cc&quot;, &quot;acd&quot;, &quot;ac&quot;, and &quot;d&quot; are consistent.
41+
</pre>
42+
43+
<p>&nbsp;</p>
44+
<p><strong>Constraints:</strong></p>
45+
46+
<ul>
47+
<li><code>1 &lt;= words.length &lt;= 10<sup>4</sup></code></li>
48+
<li><code>1 &lt;= allowed.length &lt;=<sup> </sup>26</code></li>
49+
<li><code>1 &lt;= words[i].length &lt;= 10</code></li>
50+
<li>The characters in <code>allowed</code> are <strong>distinct</strong>.</li>
51+
<li><code>words[i]</code> and <code>allowed</code> contain only lowercase English letters.</li>
52+
</ul>
53+
54+
### Related Topics
55+
[[String](../../tag/string/README.md)]
56+
57+
### Hints
58+
<details>
59+
<summary>Hint 1</summary>
60+
A string is incorrect if it contains a character that is not allowed
61+
</details>
62+
63+
<details>
64+
<summary>Hint 2</summary>
65+
Constraints are small enough for brute force
66+
</details>

problems/decode-string/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@
1313

1414
<p>Given an encoded string, return its decoded string.</p>
1515

16-
<p>The encoding rule is: <code>k[encoded_string]</code>, where the <i>encoded_string</i> inside the square brackets is being repeated exactly <i>k</i> times. Note that <i>k</i> is guaranteed to be a positive integer.</p>
16+
<p>The encoding rule is: <code>k[encoded_string]</code>, where the <code>encoded_string</code> inside the square brackets is being repeated exactly <code>k</code> times. Note that <code>k</code> is guaranteed to be a positive integer.</p>
1717

1818
<p>You may assume that the input string is always valid; No extra white spaces, square brackets are well-formed, etc.</p>
1919

20-
<p>Furthermore, you may assume that the original data does not contain any digits and that digits are only for those repeat numbers, <i>k</i>. For example, there won&#39;t be input like <code>3a</code> or <code>2[4]</code>.</p>
20+
<p>Furthermore, you may assume that the original data does not contain any digits and that digits are only for those repeat numbers, <code>k</code>. For example, there won&#39;t be input like <code>3a</code> or <code>2[4]</code>.</p>
2121

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

0 commit comments

Comments
 (0)