Skip to content

Commit b7fdc4b

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

File tree

60 files changed

+998
-247
lines changed

Some content is hidden

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

60 files changed

+998
-247
lines changed

README.md

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,17 @@ LeetCode Problems' Solutions
7070

7171
| # | Title | Solution | Difficulty |
7272
| :-: | - | - | :-: |
73+
| <span id="1553">1553</span> | [Minimum Number of Days to Eat N Oranges](https://leetcode.com/problems/minimum-number-of-days-to-eat-n-oranges "吃掉 N 个橘子的最少天数") | [Go](problems/minimum-number-of-days-to-eat-n-oranges) | Hard |
74+
| <span id="1552">1552</span> | [Magnetic Force Between Two Balls](https://leetcode.com/problems/magnetic-force-between-two-balls "两球之间的磁力") | [Go](problems/magnetic-force-between-two-balls) | Medium |
75+
| <span id="1551">1551</span> | [Minimum Operations to Make Array Equal](https://leetcode.com/problems/minimum-operations-to-make-array-equal "使数组中所有元素相等的最小操作数") | [Go](problems/minimum-operations-to-make-array-equal) | Medium |
76+
| <span id="1550">1550</span> | [Three Consecutive Odds](https://leetcode.com/problems/three-consecutive-odds "存在连续三个奇数的数组") | [Go](problems/three-consecutive-odds) | Easy |
77+
| <span id="1549">1549</span> | [The Most Recent Orders for Each Product](https://leetcode.com/problems/the-most-recent-orders-for-each-product) 🔒 | [MySQL](problems/the-most-recent-orders-for-each-product) | Medium |
78+
| <span id="1548">1548</span> | [The Most Similar Path in a Graph](https://leetcode.com/problems/the-most-similar-path-in-a-graph) 🔒 | [Go](problems/the-most-similar-path-in-a-graph) | Hard |
7379
| <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 |
7480
| <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 |
7581
| <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 |
7682
| <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 |
83+
| <span id="1543">1543</span> | [Fix Product Name Format](https://leetcode.com/problems/fix-product-name-format "产品名称格式修复") 🔒 | [MySQL](problems/fix-product-name-format) | Easy |
7884
| <span id="1542">1542</span> | [Find Longest Awesome Substring](https://leetcode.com/problems/find-longest-awesome-substring "找出最长的超赞子字符串") | [Go](problems/find-longest-awesome-substring) | Hard |
7985
| <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 |
8086
| <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 |
@@ -100,13 +106,13 @@ LeetCode Problems' Solutions
100106
| <span id="1520">1520</span> | [Maximum Number of Non-Overlapping Substrings](https://leetcode.com/problems/maximum-number-of-non-overlapping-substrings "最多的不重叠子字符串") | [Go](problems/maximum-number-of-non-overlapping-substrings) | Hard |
101107
| <span id="1519">1519</span> | [Number of Nodes in the Sub-Tree With the Same Label](https://leetcode.com/problems/number-of-nodes-in-the-sub-tree-with-the-same-label "子树中标签相同的节点数") | [Go](problems/number-of-nodes-in-the-sub-tree-with-the-same-label) | Medium |
102108
| <span id="1518">1518</span> | [Water Bottles](https://leetcode.com/problems/water-bottles "换酒问题") | [Go](problems/water-bottles) | Easy |
103-
| <span id="1517">1517</span> | [Find Users With Valid E-Mails](https://leetcode.com/problems/find-users-with-valid-e-mails) 🔒 | [MySQL](problems/find-users-with-valid-e-mails) | Easy |
104-
| <span id="1516">1516</span> | [Move Sub-Tree of N-Ary Tree](https://leetcode.com/problems/move-sub-tree-of-n-ary-tree) 🔒 | [Go](problems/move-sub-tree-of-n-ary-tree) | Hard |
109+
| <span id="1517">1517</span> | [Find Users With Valid E-Mails](https://leetcode.com/problems/find-users-with-valid-e-mails "查找拥有有效邮箱的用户") 🔒 | [MySQL](problems/find-users-with-valid-e-mails) | Easy |
110+
| <span id="1516">1516</span> | [Move Sub-Tree of N-Ary Tree](https://leetcode.com/problems/move-sub-tree-of-n-ary-tree "移动 N 叉树的子树") 🔒 | [Go](problems/move-sub-tree-of-n-ary-tree) | Hard |
105111
| <span id="1515">1515</span> | [Best Position for a Service Centre](https://leetcode.com/problems/best-position-for-a-service-centre "服务中心的最佳位置") | [Go](problems/best-position-for-a-service-centre) | Hard |
106112
| <span id="1514">1514</span> | [Path with Maximum Probability](https://leetcode.com/problems/path-with-maximum-probability "概率最大的路径") | [Go](problems/path-with-maximum-probability) | Medium |
107113
| <span id="1513">1513</span> | [Number of Substrings With Only 1s](https://leetcode.com/problems/number-of-substrings-with-only-1s "仅含 1 的子串数") | [Go](problems/number-of-substrings-with-only-1s) | Medium |
108114
| <span id="1512">1512</span> | [Number of Good Pairs](https://leetcode.com/problems/number-of-good-pairs "好数对的数目") | [Go](problems/number-of-good-pairs) | Easy |
109-
| <span id="1511">1511</span> | [Customer Order Frequency](https://leetcode.com/problems/customer-order-frequency) 🔒 | [MySQL](problems/customer-order-frequency) | Easy |
115+
| <span id="1511">1511</span> | [Customer Order Frequency](https://leetcode.com/problems/customer-order-frequency "消费者下单频率") 🔒 | [MySQL](problems/customer-order-frequency) | Easy |
110116
| <span id="1510">1510</span> | [Stone Game IV](https://leetcode.com/problems/stone-game-iv "石子游戏 IV") | [Go](problems/stone-game-iv) | Hard |
111117
| <span id="1509">1509</span> | [Minimum Difference Between Largest and Smallest Value in Three Moves](https://leetcode.com/problems/minimum-difference-between-largest-and-smallest-value-in-three-moves "三次操作后最大值与最小值的最小差") | [Go](problems/minimum-difference-between-largest-and-smallest-value-in-three-moves) | Medium |
112118
| <span id="1508">1508</span> | [Range Sum of Sorted Subarray Sums](https://leetcode.com/problems/range-sum-of-sorted-subarray-sums "子数组和排序后的区间和") | [Go](problems/range-sum-of-sorted-subarray-sums) | Medium |
@@ -400,7 +406,7 @@ LeetCode Problems' Solutions
400406
| <span id="1220">1220</span> | [Count Vowels Permutation](https://leetcode.com/problems/count-vowels-permutation "统计元音字母序列的数目") | [Go](problems/count-vowels-permutation) | Hard |
401407
| <span id="1219">1219</span> | [Path with Maximum Gold](https://leetcode.com/problems/path-with-maximum-gold "黄金矿工") | [Go](problems/path-with-maximum-gold) | Medium |
402408
| <span id="1218">1218</span> | [Longest Arithmetic Subsequence of Given Difference](https://leetcode.com/problems/longest-arithmetic-subsequence-of-given-difference "最长定差子序列") | [Go](problems/longest-arithmetic-subsequence-of-given-difference) | Medium |
403-
| <span id="1217">1217</span> | [Play with Chips](https://leetcode.com/problems/play-with-chips "玩筹码") | [Go](problems/play-with-chips) | Easy |
409+
| <span id="1217">1217</span> | [Minimum Cost to Move Chips to The Same Position](https://leetcode.com/problems/minimum-cost-to-move-chips-to-the-same-position "玩筹码") | [Go](problems/minimum-cost-to-move-chips-to-the-same-position) | Easy |
404410
| <span id="1216">1216</span> | [Valid Palindrome III](https://leetcode.com/problems/valid-palindrome-iii "验证回文字符串 III") 🔒 | [Go](problems/valid-palindrome-iii) | Hard |
405411
| <span id="1215">1215</span> | [Stepping Numbers](https://leetcode.com/problems/stepping-numbers "步进数") 🔒 | [Go](problems/stepping-numbers) | Medium |
406412
| <span id="1214">1214</span> | [Two Sum BSTs](https://leetcode.com/problems/two-sum-bsts "查找两棵二叉搜索树之和") 🔒 | [Go](problems/two-sum-bsts) | Medium |

problems/can-i-win/README.md

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,34 +11,49 @@
1111

1212
## [464. Can I Win (Medium)](https://leetcode.com/problems/can-i-win "我能赢吗")
1313

14-
<p>In the "100 game," two players take turns adding, to a running total, any integer from 1..10. The player who first causes the running total to reach or exceed 100 wins. </p>
14+
<p>In the &quot;100 game&quot; two players take turns adding, to a running total, any integer from <code>1</code> to <code>10</code>. The player who first causes the running total to <strong>reach or exceed</strong> 100 wins.</p>
1515

16-
<p>What if we change the game so that players cannot re-use integers? </p>
16+
<p>What if we change the game so that players <strong>cannot</strong> re-use integers?</p>
1717

18-
<p>For example, two players might take turns drawing from a common pool of numbers of 1..15 without replacement until they reach a total >= 100.</p>
18+
<p>For example, two players might take turns drawing from a common pool of numbers from 1 to 15 without replacement until they reach a total &gt;= 100.</p>
1919

20-
<p>Given an integer <code>maxChoosableInteger</code> and another integer <code>desiredTotal</code>, determine if the first player to move can force a win, assuming both players play optimally. </p>
20+
<p>Given two integers maxChoosableInteger and&nbsp;desiredTotal, return <code>true</code> if the first player to move can force a win, otherwise return <code>false</code>.&nbsp;Assume&nbsp;both players play <strong>optimally</strong>.</p>
2121

22-
<p>You can always assume that <code>maxChoosableInteger</code> will not be larger than 20 and <code>desiredTotal</code> will not be larger than 300.
23-
</p>
22+
<p>&nbsp;</p>
23+
<p><strong>Example 1:</strong></p>
2424

25-
<p><b>Example</b>
2625
<pre>
27-
<b>Input:</b>
28-
maxChoosableInteger = 10
29-
desiredTotal = 11
30-
31-
<b>Output:</b>
32-
false
33-
34-
<b>Explanation:</b>
26+
<strong>Input:</strong> maxChoosableInteger = 10, desiredTotal = 11
27+
<strong>Output:</strong> false
28+
<strong>Explanation:</strong>
3529
No matter which integer the first player choose, the first player will lose.
3630
The first player can choose an integer from 1 up to 10.
3731
If the first player choose 1, the second player can only choose integers from 2 up to 10.
38-
The second player will win by choosing 10 and get a total = 11, which is >= desiredTotal.
32+
The second player will win by choosing 10 and get a total = 11, which is &gt;= desiredTotal.
3933
Same with other integers chosen by the first player, the second player will always win.
4034
</pre>
41-
</p>
35+
36+
<p><strong>Example 2:</strong></p>
37+
38+
<pre>
39+
<strong>Input:</strong> maxChoosableInteger = 10, desiredTotal = 0
40+
<strong>Output:</strong> true
41+
</pre>
42+
43+
<p><strong>Example 3:</strong></p>
44+
45+
<pre>
46+
<strong>Input:</strong> maxChoosableInteger = 10, desiredTotal = 1
47+
<strong>Output:</strong> true
48+
</pre>
49+
50+
<p>&nbsp;</p>
51+
<p><strong>Constraints:</strong></p>
52+
53+
<ul>
54+
<li><code>1 &lt;=&nbsp;maxChoosableInteger &lt;= 20</code></li>
55+
<li><code>0 &lt;=&nbsp;desiredTotal &lt;= 300</code></li>
56+
</ul>
4257

4358
### Related Topics
4459
[[Minimax](../../tag/minimax/README.md)]

problems/combinations/README.md

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,13 @@
1313

1414
<p>Given two integers <em>n</em> and <em>k</em>, return all possible combinations of <em>k</em> numbers out of 1 ... <em>n</em>.</p>
1515

16-
<p><strong>Example:</strong></p>
16+
<p>You may return the answer in <strong>any order</strong>.</p>
17+
18+
<p>&nbsp;</p>
19+
<p><strong>Example 1:</strong></p>
1720

1821
<pre>
19-
<strong>Input:</strong>&nbsp;n = 4, k = 2
22+
<strong>Input:</strong> n = 4, k = 2
2023
<strong>Output:</strong>
2124
[
2225
[2,4],
@@ -28,6 +31,21 @@
2831
]
2932
</pre>
3033

34+
<p><strong>Example 2:</strong></p>
35+
36+
<pre>
37+
<strong>Input:</strong> n = 1, k = 1
38+
<strong>Output:</strong> [[1]]
39+
</pre>
40+
41+
<p>&nbsp;</p>
42+
<p><strong>Constraints:</strong></p>
43+
44+
<ul>
45+
<li><code>1 &lt;= n &lt;= 20</code></li>
46+
<li><code>1 &lt;= k &lt;= n</code></li>
47+
</ul>
48+
3149
### Related Topics
3250
[[Backtracking](../../tag/backtracking/README.md)]
3351

problems/course-schedule-ii/README.md

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

88
[< Previous](../minimum-size-subarray-sum "Minimum Size Subarray Sum")
99

10-
[Next >](../add-and-search-word-data-structure-design "Add and Search Word - Data structure design")
10+
[Next >](../design-add-and-search-words-data-structure "Design Add and Search Words Data Structure")
1111

1212
## [210. Course Schedule II (Medium)](https://leetcode.com/problems/course-schedule-ii "课程表 II")
1313

problems/customer-order-frequency/README.md

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

1010
[Next >](../number-of-good-pairs "Number of Good Pairs")
1111

12-
## [1511. Customer Order Frequency (Easy)](https://leetcode.com/problems/customer-order-frequency "")
12+
## [1511. Customer Order Frequency (Easy)](https://leetcode.com/problems/customer-order-frequency "消费者下单频率")
1313

1414

Lines changed: 68 additions & 0 deletions
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](../course-schedule-ii "Course Schedule II")
9+
                
10+
[Next >](../word-search-ii "Word Search II")
11+
12+
## [211. Design Add and Search Words Data Structure (Medium)](https://leetcode.com/problems/design-add-and-search-words-data-structure "添加与搜索单词 - 数据结构设计")
13+
14+
<p>You should design a data structure that supports adding new words and finding if a string matches any previously added string.</p>
15+
16+
<p>Implement the <code>WordDictionary</code> class:</p>
17+
18+
<ul>
19+
<li><code>WordDictionary()</code>&nbsp;Initializes the object.</li>
20+
<li><code>void addWord(word)</code> adds <code>word</code> to the data structure, it can be matched later.</li>
21+
<li><code>bool search(word)</code>&nbsp;returns <code>true</code> if there is any string in the data structure that matches <code>word</code>&nbsp;or <code>false</code> otherwise. <code>word</code> may contain dots <code>&#39;.&#39;</code> where dots can be matched with any letter.</li>
22+
</ul>
23+
24+
<p>&nbsp;</p>
25+
<p><strong>Example:</strong></p>
26+
27+
<pre>
28+
<strong>Input</strong>
29+
[&quot;WordDictionary&quot;,&quot;addWord&quot;,&quot;addWord&quot;,&quot;addWord&quot;,&quot;search&quot;,&quot;search&quot;,&quot;search&quot;,&quot;search&quot;]
30+
[[],[&quot;bad&quot;],[&quot;dad&quot;],[&quot;mad&quot;],[&quot;pad&quot;],[&quot;bad&quot;],[&quot;.ad&quot;],[&quot;b..&quot;]]
31+
<strong>Output</strong>
32+
[null,null,null,null,false,true,true,true]
33+
34+
<strong>Explanation</strong>
35+
WordDictionary wordDictionary = new WordDictionary();
36+
wordDictionary.addWord(&quot;bad&quot;);
37+
wordDictionary.addWord(&quot;dad&quot;);
38+
wordDictionary.addWord(&quot;mad&quot;);
39+
wordDictionary.search(&quot;pad&quot;); // return False
40+
wordDictionary.search(&quot;bad&quot;); // return True
41+
wordDictionary.search(&quot;.ad&quot;); // return True
42+
wordDictionary.search(&quot;b..&quot;); // return True
43+
</pre>
44+
45+
<p>&nbsp;</p>
46+
<p><strong>Constraints:</strong></p>
47+
48+
<ul>
49+
<li><code>1 &lt;= word.length &lt;= 500</code></li>
50+
<li><code>word</code> in <code>addWord</code> consists lower-case English letters.</li>
51+
<li><code>word</code> in <code>search</code> consist of&nbsp; &#39;.&#39; or lower-case English letters.</li>
52+
<li>At most <code>50000</code>&nbsp;calls will be made to <code>addWord</code>&nbsp;and <code>search</code> .</li>
53+
</ul>
54+
55+
### Related Topics
56+
[[Design](../../tag/design/README.md)]
57+
[[Trie](../../tag/trie/README.md)]
58+
[[Backtracking](../../tag/backtracking/README.md)]
59+
60+
### Similar Questions
61+
1. [Implement Trie (Prefix Tree)](../implement-trie-prefix-tree) (Medium)
62+
1. [Prefix and Suffix Search](../prefix-and-suffix-search) (Hard)
63+
64+
### Hints
65+
<details>
66+
<summary>Hint 1</summary>
67+
You should be familiar with how a Trie works. If not, please work on this problem: <a href="https://leetcode.com/problems/implement-trie-prefix-tree/">Implement Trie (Prefix Tree)</a> first.
68+
</details>

problems/distribute-candies/README.md

Lines changed: 50 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,34 +11,66 @@
1111

1212
## [575. Distribute Candies (Easy)](https://leetcode.com/problems/distribute-candies "分糖果")
1313

14-
Given an integer array with <b>even</b> length, where different numbers in this array represent different <b>kinds</b> of candies. Each number means one candy of the corresponding kind. You need to distribute these candies <b>equally</b> in number to brother and sister. Return the maximum number of <b>kinds</b> of candies the sister could gain.
14+
<p>You have <code>n</code>&nbsp;<code>candies</code> of&nbsp;different types, the <code>i<sup>th</sup></code> candy is of type <code>candies[i]</code>.</p>
15+
16+
<p>You want to distribute the candies equally between a sister and a brother so that each of them gets <code>n / 2</code>&nbsp;candies (<code>n</code> is even). The sister loves to collect different types of candies, so you want to give her the <strong>maximum number of different types</strong> of candies.</p>
17+
18+
<p>Return <em>the maximum number of different types</em> of candies you can give to the sister.</p>
19+
20+
<ol>
21+
</ol>
22+
23+
<p>&nbsp;</p>
24+
<p><strong>Example 1:</strong></p>
1525

16-
<p><b>Example 1:</b><br />
1726
<pre>
18-
<b>Input:</b> candies = [1,1,2,2,3,3]
19-
<b>Output:</b> 3
20-
<b>Explanation:</b>
27+
<strong>Input:</strong> candies = [1,1,2,2,3,3]
28+
<strong>Output:</strong> 3
29+
<strong>Explanation:</strong>
2130
There are three different kinds of candies (1, 2 and 3), and two candies for each kind.
2231
Optimal distribution: The sister has candies [1,2,3] and the brother has candies [1,2,3], too.
2332
The sister has three different kinds of candies.
2433
</pre>
25-
</p>
2634

27-
<p><b>Example 2:</b><br />
35+
<p><strong>Example 2:</strong></p>
36+
2837
<pre>
29-
<b>Input:</b> candies = [1,1,2,3]
30-
<b>Output:</b> 2
31-
<b>Explanation:</b> For example, the sister has candies [2,3] and the brother has candies [1,1].
32-
The sister has two different kinds of candies, the brother has only one kind of candies.
38+
<strong>Input:</strong> candies = [1,1,2,3]
39+
<strong>Output:</strong> 2
40+
<strong>Explanation:</strong> For example, the sister has candies [2,3] and the brother has candies [1,1].
41+
The sister has two different kinds of candies, the brother has only one kind of candies.
3342
</pre>
34-
</p>
3543

36-
<p><b>Note:</b>
37-
<ol>
38-
<li>The length of the given array is in range [2, 10,000], and will be even.</li>
39-
<li>The number in given array is in range [-100,000, 100,000].</li>
40-
<ol>
41-
</p>
44+
<p><strong>Example 3:</strong></p>
45+
46+
<pre>
47+
<strong>Input:</strong> candies = [1,1]
48+
<strong>Output:</strong> 1
49+
</pre>
50+
51+
<p><strong>Example 4:</strong></p>
52+
53+
<pre>
54+
<strong>Input:</strong> candies = [1,11]
55+
<strong>Output:</strong> 1
56+
</pre>
57+
58+
<p><strong>Example 5:</strong></p>
59+
60+
<pre>
61+
<strong>Input:</strong> candies = [2,2]
62+
<strong>Output:</strong> 1
63+
</pre>
64+
65+
<p>&nbsp;</p>
66+
<p><strong>Constraints:</strong></p>
67+
68+
<ul>
69+
<li><code>n == candies.length</code></li>
70+
<li><code>2 &lt;= n &lt;= 10^4</code></li>
71+
<li><code>n</code>&nbsp;is even.</li>
72+
<li><code>-10^5 &lt;= candies[i] &lt;= 10^5</code></li>
73+
</ul>
4274

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

0 commit comments

Comments
 (0)