Skip to content

Commit 0e93785

Browse files
author
Shuo
committed
A: new
1 parent a7d9333 commit 0e93785

File tree

24 files changed

+698
-24
lines changed

24 files changed

+698
-24
lines changed

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,16 @@ LeetCode Problems' Solutions
7070

7171
| # | Title | Solution | Difficulty |
7272
| :-: | - | - | :-: |
73+
| <span id="1547">1547</span> | [Minimum Cost to Cut a Stick](https://leetcode.com/problems/minimum-cost-to-cut-a-stick "切棍子的最小成本") | [Go](problems/minimum-cost-to-cut-a-stick) | Hard |
74+
| <span id="1546">1546</span> | [Maximum Number of Non-Overlapping Subarrays With Sum Equals Target](https://leetcode.com/problems/maximum-number-of-non-overlapping-subarrays-with-sum-equals-target "和为目标值的最大数目不重叠非空子数组数目") | [Go](problems/maximum-number-of-non-overlapping-subarrays-with-sum-equals-target) | Medium |
75+
| <span id="1545">1545</span> | [Find Kth Bit in Nth Binary String](https://leetcode.com/problems/find-kth-bit-in-nth-binary-string "找出第 N 个二进制字符串中的第 K 位") | [Go](problems/find-kth-bit-in-nth-binary-string) | Medium |
76+
| <span id="1544">1544</span> | [Make The String Great](https://leetcode.com/problems/make-the-string-great "整理字符串") | [Go](problems/make-the-string-great) | Easy |
77+
| <span id="1543">1543</span> | [Fix Product Name Format](https://leetcode.com/problems/fix-product-name-format) 🔒 | [MySQL](problems/fix-product-name-format) | Easy |
78+
| <span id="1542">1542</span> | [Find Longest Awesome Substring](https://leetcode.com/problems/find-longest-awesome-substring "找出最长的超赞子字符串") | [Go](problems/find-longest-awesome-substring) | Hard |
79+
| <span id="1541">1541</span> | [Minimum Insertions to Balance a Parentheses String](https://leetcode.com/problems/minimum-insertions-to-balance-a-parentheses-string "平衡括号字符串的最少插入次数") | [Go](problems/minimum-insertions-to-balance-a-parentheses-string) | Medium |
80+
| <span id="1540">1540</span> | [Can Convert String in K Moves](https://leetcode.com/problems/can-convert-string-in-k-moves "K 次操作转变字符串") | [Go](problems/can-convert-string-in-k-moves) | Medium |
81+
| <span id="1539">1539</span> | [Kth Missing Positive Number](https://leetcode.com/problems/kth-missing-positive-number "第 k 个缺失的正整数") | [Go](problems/kth-missing-positive-number) | Easy |
82+
| <span id="1538">1538</span> | [Guess the Majority in a Hidden Array](https://leetcode.com/problems/guess-the-majority-in-a-hidden-array) 🔒 | [Go](problems/guess-the-majority-in-a-hidden-array) | Medium |
7383
| <span id="1537">1537</span> | [Get the Maximum Score](https://leetcode.com/problems/get-the-maximum-score "最大得分") | [Go](problems/get-the-maximum-score) | Hard |
7484
| <span id="1536">1536</span> | [Minimum Swaps to Arrange a Binary Grid](https://leetcode.com/problems/minimum-swaps-to-arrange-a-binary-grid "排布二进制网格的最少交换次数") | [Go](problems/minimum-swaps-to-arrange-a-binary-grid) | Medium |
7585
| <span id="1535">1535</span> | [Find the Winner of an Array Game](https://leetcode.com/problems/find-the-winner-of-an-array-game "找出数组游戏的赢家") | [Go](problems/find-the-winner-of-an-array-game) | Medium |

problems/binary-tree-pruning/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ The diagram on the right represents the answer.
5050
<p><strong>Note: </strong></p>
5151

5252
<ul>
53-
<li>The binary tree&nbsp;will&nbsp;have&nbsp;at&nbsp;most <code>100 nodes</code>.</li>
53+
<li>The binary tree&nbsp;will&nbsp;have&nbsp;at&nbsp;most <code>200 nodes</code>.</li>
5454
<li>The value of each node will only be <code>0</code> or <code>1</code>.</li>
5555
</ul>
5656

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
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](../kth-missing-positive-number "Kth Missing Positive Number")
9+
                
10+
[Next >](../minimum-insertions-to-balance-a-parentheses-string "Minimum Insertions to Balance a Parentheses String")
11+
12+
## [1540. Can Convert String in K Moves (Medium)](https://leetcode.com/problems/can-convert-string-in-k-moves "K 次操作转变字符串")
13+
14+
<p>Given two strings&nbsp;<code>s</code>&nbsp;and&nbsp;<code>t</code>, your goal is to convert&nbsp;<code>s</code>&nbsp;into&nbsp;<code>t</code>&nbsp;in&nbsp;<code>k</code><strong>&nbsp;</strong>moves or less.</p>
15+
16+
<p>During the&nbsp;<code>i<sup>th</sup></code>&nbsp;(<font face="monospace"><code>1 &lt;= i &lt;= k</code>)&nbsp;</font>move you can:</p>
17+
18+
<ul>
19+
<li>Choose any index&nbsp;<code>j</code>&nbsp;(1-indexed) from&nbsp;<code>s</code>, such that&nbsp;<code>1 &lt;= j &lt;= s.length</code>&nbsp;and <code>j</code>&nbsp;has not been chosen in any previous move,&nbsp;and shift the character at that index&nbsp;<code>i</code>&nbsp;times.</li>
20+
<li>Do nothing.</li>
21+
</ul>
22+
23+
<p>Shifting a character means replacing it by the next letter in the alphabet&nbsp;(wrapping around so that&nbsp;<code>&#39;z&#39;</code>&nbsp;becomes&nbsp;<code>&#39;a&#39;</code>). Shifting a character by&nbsp;<code>i</code>&nbsp;means applying the shift operations&nbsp;<code>i</code>&nbsp;times.</p>
24+
25+
<p>Remember that any index&nbsp;<code>j</code>&nbsp;can be picked at most once.</p>
26+
27+
<p>Return&nbsp;<code>true</code>&nbsp;if it&#39;s possible to convert&nbsp;<code>s</code>&nbsp;into&nbsp;<code>t</code>&nbsp;in no more than&nbsp;<code>k</code>&nbsp;moves, otherwise return&nbsp;<code>false</code>.</p>
28+
29+
<p>&nbsp;</p>
30+
<p><strong>Example 1:</strong></p>
31+
32+
<pre>
33+
<strong>Input:</strong> s = &quot;input&quot;, t = &quot;ouput&quot;, k = 9
34+
<strong>Output:</strong> true
35+
<b>Explanation: </b>In the 6th move, we shift &#39;i&#39; 6 times to get &#39;o&#39;. And in the 7th move we shift &#39;n&#39; to get &#39;u&#39;.
36+
</pre>
37+
38+
<p><strong>Example 2:</strong></p>
39+
40+
<pre>
41+
<strong>Input:</strong> s = &quot;abc&quot;, t = &quot;bcd&quot;, k = 10
42+
<strong>Output:</strong> false
43+
<strong>Explanation: </strong>We need to shift each character in s one time to convert it into t. We can shift &#39;a&#39; to &#39;b&#39; during the 1st move. However, there is no way to shift the other characters in the remaining moves to obtain t from s.
44+
</pre>
45+
46+
<p><strong>Example 3:</strong></p>
47+
48+
<pre>
49+
<strong>Input:</strong> s = &quot;aab&quot;, t = &quot;bbb&quot;, k = 27
50+
<strong>Output:</strong> true
51+
<b>Explanation: </b>In the 1st move, we shift the first &#39;a&#39; 1 time to get &#39;b&#39;. In the 27th move, we shift the second &#39;a&#39; 27 times to get &#39;b&#39;.
52+
</pre>
53+
54+
<p>&nbsp;</p>
55+
<p><strong>Constraints:</strong></p>
56+
57+
<ul>
58+
<li><code>1 &lt;= s.length, t.length &lt;= 10^5</code></li>
59+
<li><code>0 &lt;= k &lt;= 10^9</code></li>
60+
<li><code>s</code>, <code>t</code> contain&nbsp;only lowercase English letters.</li>
61+
</ul>
62+
63+
### Related Topics
64+
[[Greedy](../../tag/greedy/README.md)]
65+
[[String](../../tag/string/README.md)]
66+
67+
### Hints
68+
<details>
69+
<summary>Hint 1</summary>
70+
Observe that shifting a letter x times has the same effect of shifting the letter x + 26 times.
71+
</details>
72+
73+
<details>
74+
<summary>Hint 2</summary>
75+
You need to check whether k is large enough to cover all shifts with the same remainder after modulo 26.
76+
</details>

problems/count-of-smaller-numbers-after-self/README.md

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,27 @@
1313

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

16-
<p><b>Example:</b></p>
16+
<p>&nbsp;</p>
17+
<p><strong>Example 1:</strong></p>
1718

1819
<pre>
19-
<strong>Input:</strong> [5,2,6,1]
20-
<strong>Output:</strong> <code>[2,1,1,0]
21-
<strong>Explanation:</strong></code>
20+
<strong>Input:</strong> nums = [5,2,6,1]
21+
<strong>Output:</strong> [2,1,1,0]
22+
<strong>Explanation:</strong>
2223
To the right of 5 there are <b>2</b> smaller elements (2 and 1).
2324
To the right of 2 there is only <b>1</b> smaller element (1).
2425
To the right of 6 there is <b>1</b> smaller element (1).
2526
To the right of 1 there is <b>0</b> smaller element.
2627
</pre>
2728

29+
<p>&nbsp;</p>
30+
<p><strong>Constraints:</strong></p>
31+
32+
<ul>
33+
<li><code>0 &lt;= nums.length &lt;= 10^5</code></li>
34+
<li><code>-10^4&nbsp;&lt;= nums[i] &lt;= 10^4</code></li>
35+
</ul>
36+
2837
### Related Topics
2938
[[Sort](../../tag/sort/README.md)]
3039
[[Binary Indexed Tree](../../tag/binary-indexed-tree/README.md)]
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
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](../make-the-string-great "Make The String Great")
9+
                
10+
[Next >](../maximum-number-of-non-overlapping-subarrays-with-sum-equals-target "Maximum Number of Non-Overlapping Subarrays With Sum Equals Target")
11+
12+
## [1545. Find Kth Bit in Nth Binary String (Medium)](https://leetcode.com/problems/find-kth-bit-in-nth-binary-string "找出第 N 个二进制字符串中的第 K 位")
13+
14+
<p>Given two positive integers&nbsp;<code>n</code>&nbsp;and <code>k</code>,&nbsp;the binary string&nbsp;&nbsp;<code>S<sub>n</sub></code>&nbsp;is formed as follows:</p>
15+
16+
<ul>
17+
<li><code>S<sub>1</sub>&nbsp;= &quot;0&quot;</code></li>
18+
<li><code>S<sub><span style="font-size: 10.8333px;">i</span></sub>&nbsp;=&nbsp;S<sub><span style="font-size: 10.8333px;">i-1</span></sub>&nbsp;+ &quot;1&quot; + reverse(invert(S<sub><span style="font-size: 10.8333px;">i-1</span></sub>))</code>&nbsp;for&nbsp;<code>i &gt; 1</code></li>
19+
</ul>
20+
21+
<p>Where&nbsp;<code>+</code>&nbsp;denotes the concatenation operation,&nbsp;<code>reverse(x)</code>&nbsp;returns the reversed string <font face="monospace">x,</font>&nbsp;and&nbsp;<code>invert(x)</code>&nbsp;inverts all the bits in <font face="monospace">x</font> (0 changes to 1 and 1 changes to 0).</p>
22+
23+
<p>For example, the first 4 strings in the above sequence are:</p>
24+
25+
<ul>
26+
<li><code>S<sub>1&nbsp;</sub>= &quot;0&quot;</code></li>
27+
<li><code>S<sub>2&nbsp;</sub>= &quot;0<strong>1</strong>1&quot;</code></li>
28+
<li><code>S<sub>3&nbsp;</sub>= &quot;011<strong>1</strong>001&quot;</code></li>
29+
<li><code>S<sub>4</sub> = &quot;0111001<strong>1</strong>0110001&quot;</code></li>
30+
</ul>
31+
32+
<p>Return <em>the</em> <code>k<sup>th</sup></code> <em>bit</em> <em>in</em>&nbsp;<code>S<sub>n</sub></code>. It is guaranteed that&nbsp;<code>k</code>&nbsp;is valid for the given&nbsp;<code>n</code>.</p>
33+
34+
<p>&nbsp;</p>
35+
<p><strong>Example 1:</strong></p>
36+
37+
<pre>
38+
<strong>Input:</strong> n = 3, k = 1
39+
<strong>Output:</strong> &quot;0&quot;
40+
<strong>Explanation: </strong>S<sub>3</sub>&nbsp;is &quot;<strong><u>0</u></strong>111001&quot;. The first bit is &quot;0&quot;.
41+
</pre>
42+
43+
<p><strong>Example 2:</strong></p>
44+
45+
<pre>
46+
<strong>Input:</strong> n = 4, k = 11
47+
<strong>Output:</strong> &quot;1&quot;
48+
<strong>Explanation: </strong>S<sub>4</sub>&nbsp;is &quot;0111001101<strong><u>1</u></strong>0001&quot;. The 11th bit is &quot;1&quot;.
49+
</pre>
50+
51+
<p><strong>Example 3:</strong></p>
52+
53+
<pre>
54+
<strong>Input:</strong> n = 1, k = 1
55+
<strong>Output:</strong> &quot;0&quot;
56+
</pre>
57+
58+
<p><strong>Example 4:</strong></p>
59+
60+
<pre>
61+
<strong>Input:</strong> n = 2, k = 3
62+
<strong>Output:</strong> &quot;1&quot;
63+
</pre>
64+
65+
<p>&nbsp;</p>
66+
<p><strong>Constraints:</strong></p>
67+
68+
<ul>
69+
<li><code>1 &lt;= n &lt;= 20</code></li>
70+
<li><code>1 &lt;= k &lt;= 2<sup>n</sup> - 1</code></li>
71+
</ul>
72+
73+
### Related Topics
74+
[[String](../../tag/string/README.md)]
75+
76+
### Hints
77+
<details>
78+
<summary>Hint 1</summary>
79+
Since n is small, we can simply simulate the process of constructing S1 to Sn.
80+
</details>
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
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](../minimum-insertions-to-balance-a-parentheses-string "Minimum Insertions to Balance a Parentheses String")
9+
                
10+
[Next >](../fix-product-name-format "Fix Product Name Format")
11+
12+
## [1542. Find Longest Awesome Substring (Hard)](https://leetcode.com/problems/find-longest-awesome-substring "找出最长的超赞子字符串")
13+
14+
<p>Given a string <code>s</code>. An <em>awesome</em> substring is a non-empty substring of <code>s</code> such that we can make any number of swaps in order to make it palindrome.</p>
15+
16+
<p>Return the length of the maximum length <strong>awesome substring</strong> of <code>s</code>.</p>
17+
18+
<p>&nbsp;</p>
19+
<p><strong>Example 1:</strong></p>
20+
21+
<pre>
22+
<strong>Input:</strong> s = &quot;3242415&quot;
23+
<strong>Output:</strong> 5
24+
<strong>Explanation:</strong> &quot;24241&quot; is the longest awesome substring, we can form the palindrome &quot;24142&quot; with some swaps.
25+
</pre>
26+
27+
<p><strong>Example 2:</strong></p>
28+
29+
<pre>
30+
<strong>Input:</strong> s = &quot;12345678&quot;
31+
<strong>Output:</strong> 1
32+
</pre>
33+
34+
<p><strong>Example 3:</strong></p>
35+
36+
<pre>
37+
<strong>Input:</strong> s = &quot;213123&quot;
38+
<strong>Output:</strong> 6
39+
<strong>Explanation:</strong> &quot;213123&quot; is the longest awesome substring, we can form the palindrome &quot;231132&quot; with some swaps.
40+
</pre>
41+
42+
<p><strong>Example 4:</strong></p>
43+
44+
<pre>
45+
<strong>Input:</strong> s = &quot;00&quot;
46+
<strong>Output:</strong> 2
47+
</pre>
48+
49+
<p>&nbsp;</p>
50+
<p><strong>Constraints:</strong></p>
51+
52+
<ul>
53+
<li><code>1 &lt;= s.length &lt;= 10^5</code></li>
54+
<li><code>s</code> consists only of digits.</li>
55+
</ul>
56+
57+
### Related Topics
58+
[[Bit Manipulation](../../tag/bit-manipulation/README.md)]
59+
[[String](../../tag/string/README.md)]
60+
61+
### Hints
62+
<details>
63+
<summary>Hint 1</summary>
64+
Given the character counts, under what conditions can a palindrome be formed ?
65+
</details>
66+
67+
<details>
68+
<summary>Hint 2</summary>
69+
From left to right, use bitwise xor-operation to compute for any prefix the number of times modulo 2 of each digit. (mask ^= (1<<(s[i]-'0')).
70+
</details>
71+
72+
<details>
73+
<summary>Hint 3</summary>
74+
Expected complexity is O(n*A) where A is the alphabet (10).
75+
</details>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
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-longest-awesome-substring "Find Longest Awesome Substring")
9+
                
10+
[Next >](../make-the-string-great "Make The String Great")
11+
12+
## [1543. Fix Product Name Format (Easy)](https://leetcode.com/problems/fix-product-name-format "")
13+
14+
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
Create table If Not Exists Sales (sale_id int, product_name varchar(30), sale_date date)
2+
;
3+
Truncate table Sales;
4+
insert into Sales (sale_id, product_name, sale_date) values ('1', 'LCPHONE', '2000-01-16');
5+
insert into Sales (sale_id, product_name, sale_date) values ('2', 'LCPhone', '2000-01-17');
6+
insert into Sales (sale_id, product_name, sale_date) values ('3', 'LcPhOnE', '2000-02-18');
7+
insert into Sales (sale_id, product_name, sale_date) values ('4', 'LCKeyCHAiN', '2000-02-19');
8+
insert into Sales (sale_id, product_name, sale_date) values ('5', 'LCKeyChain', '2000-02-28');
9+
insert into Sales (sale_id, product_name, sale_date) values ('6', 'Matryoshka', '2000-03-31');

problems/get-the-maximum-score/README.md

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

88
[< Previous](../minimum-swaps-to-arrange-a-binary-grid "Minimum Swaps to Arrange a Binary Grid")
99

10-
Next >
10+
[Next >](../guess-the-majority-in-a-hidden-array "Guess the Majority in a Hidden Array")
1111

1212
## [1537. Get the Maximum Score (Hard)](https://leetcode.com/problems/get-the-maximum-score "最大得分")
1313

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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](../get-the-maximum-score "Get the Maximum Score")
9+
                
10+
[Next >](../kth-missing-positive-number "Kth Missing Positive Number")
11+
12+
## [1538. Guess the Majority in a Hidden Array (Medium)](https://leetcode.com/problems/guess-the-majority-in-a-hidden-array "")
13+
14+
15+
16+
### Hints
17+
<details>
18+
<summary>Hint 1</summary>
19+
If you find that 2 indexes in the array (id1, id2) have the same value (nums [id1] == nums [id2]), you could infer the values of (x, y) based on the results of query (id1, id2, x, y).
20+
</details>

0 commit comments

Comments
 (0)