Skip to content

Commit 4083e8c

Browse files
author
Shuo
authored
Merge pull request #628 from openset/develop
Add: new
2 parents cb5397d + ada89d4 commit 4083e8c

File tree

36 files changed

+370
-29
lines changed

36 files changed

+370
-29
lines changed

Diff for: README.md

+7-1
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,16 @@ LeetCode Problems' Solutions
5454

5555
| # | Title | Solution | Difficulty |
5656
| :-: | - | - | :-: |
57+
| <span id="1178">1178</span> | [Number of Valid Words for Each Puzzle](https://leetcode.com/problems/number-of-valid-words-for-each-puzzle "猜字谜") | [Go](https://github.com/openset/leetcode/tree/master/problems/number-of-valid-words-for-each-puzzle) | Hard |
58+
| <span id="1177">1177</span> | [Can Make Palindrome from Substring](https://leetcode.com/problems/can-make-palindrome-from-substring "构建回文串检测") | [Go](https://github.com/openset/leetcode/tree/master/problems/can-make-palindrome-from-substring) | Medium |
59+
| <span id="1176">1176</span> | [Diet Plan Performance](https://leetcode.com/problems/diet-plan-performance "健身计划评估") | [Go](https://github.com/openset/leetcode/tree/master/problems/diet-plan-performance) | Easy |
60+
| <span id="1175">1175</span> | [Prime Arrangements](https://leetcode.com/problems/prime-arrangements "质数排列") | [Go](https://github.com/openset/leetcode/tree/master/problems/prime-arrangements) | Easy |
61+
| <span id="1174">1174</span> | [Immediate Food Delivery II](https://leetcode.com/problems/immediate-food-delivery-ii) 🔒 | [MySQL](https://github.com/openset/leetcode/tree/master/problems/immediate-food-delivery-ii) | Medium |
62+
| <span id="1173">1173</span> | [Immediate Food Delivery I](https://leetcode.com/problems/immediate-food-delivery-i) 🔒 | [MySQL](https://github.com/openset/leetcode/tree/master/problems/immediate-food-delivery-i) | Easy |
5763
| <span id="1172">1172</span> | [Dinner Plate Stacks](https://leetcode.com/problems/dinner-plate-stacks "餐盘栈") | [Go](https://github.com/openset/leetcode/tree/master/problems/dinner-plate-stacks) | Hard |
5864
| <span id="1171">1171</span> | [Remove Zero Sum Consecutive Nodes from Linked List](https://leetcode.com/problems/remove-zero-sum-consecutive-nodes-from-linked-list "从链表中删去总和值为零的连续节点") | [Go](https://github.com/openset/leetcode/tree/master/problems/remove-zero-sum-consecutive-nodes-from-linked-list) | Medium |
5965
| <span id="1170">1170</span> | [Compare Strings by Frequency of the Smallest Character](https://leetcode.com/problems/compare-strings-by-frequency-of-the-smallest-character "比较字符串最小字母出现频次") | [Go](https://github.com/openset/leetcode/tree/master/problems/compare-strings-by-frequency-of-the-smallest-character) | Easy |
60-
| <span id="1169">1169</span> | [Invalid Transactions](https://leetcode.com/problems/invalid-transactions "查询无效交易") | [Go](https://github.com/openset/leetcode/tree/master/problems/invalid-transactions) | Easy |
66+
| <span id="1169">1169</span> | [Invalid Transactions](https://leetcode.com/problems/invalid-transactions "查询无效交易") | [Go](https://github.com/openset/leetcode/tree/master/problems/invalid-transactions) | Medium |
6167
| <span id="1168">1168</span> | [Optimize Water Distribution in a Village](https://leetcode.com/problems/optimize-water-distribution-in-a-village "水资源分配优化") 🔒 | [Go](https://github.com/openset/leetcode/tree/master/problems/optimize-water-distribution-in-a-village) | Hard |
6268
| <span id="1167">1167</span> | [Minimum Cost to Connect Sticks](https://leetcode.com/problems/minimum-cost-to-connect-sticks "连接棒材的最低费用") 🔒 | [Go](https://github.com/openset/leetcode/tree/master/problems/minimum-cost-to-connect-sticks) | Medium |
6369
| <span id="1166">1166</span> | [Design File System](https://leetcode.com/problems/design-file-system "设计文件系统") 🔒 | [Go](https://github.com/openset/leetcode/tree/master/problems/design-file-system) | Medium |

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@
4444
<strong>Explanation:</strong> In this case, no transaction is done, i.e. max profit = 0.</pre>
4545

4646
### Related Topics
47-
[[Greedy](https://github.com/openset/leetcode/tree/master/tag/greedy/README.md)]
4847
[[Array](https://github.com/openset/leetcode/tree/master/tag/array/README.md)]
48+
[[Greedy](https://github.com/openset/leetcode/tree/master/tag/greedy/README.md)]
4949

5050
### Similar Questions
5151
1. [Best Time to Buy and Sell Stock](https://github.com/openset/leetcode/tree/master/problems/best-time-to-buy-and-sell-stock) (Easy)
+76
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 <[email protected]> |-->
4+
<!--|@link https://github.com/openset |-->
5+
<!--|@home https://github.com/openset/leetcode |-->
6+
<!--+----------------------------------------------------------------------+-->
7+
8+
[< Previous](https://github.com/openset/leetcode/tree/master/problems/diet-plan-performance "Diet Plan Performance")
9+
                
10+
[Next >](https://github.com/openset/leetcode/tree/master/problems/number-of-valid-words-for-each-puzzle "Number of Valid Words for Each Puzzle")
11+
12+
## 5175. Can Make Palindrome from Substring (Medium)
13+
14+
<p>Given a string <code>s</code>, we make queries on substrings of <code>s</code>.</p>
15+
16+
<p>For each query <code>queries[i] = [left, right, k]</code>, we may <strong>rearrange</strong>&nbsp;the substring <code>s[left], ..., s[right]</code>, and then choose <strong>up to</strong> <code>k</code> of them to replace with any lowercase English letter.&nbsp;</p>
17+
18+
<p>If the substring&nbsp;is possible to be a&nbsp;palindrome string after the operations above, the result of the query is <code>true</code>.&nbsp;Otherwise, the result&nbsp;is <code>false</code>.</p>
19+
20+
<p>Return an array <code>answer[]</code>, where <code>answer[i]</code> is the result of the <code>i</code>-th query <code>queries[i]</code>.</p>
21+
22+
<p>Note that: Each letter is counted <strong>individually</strong> for replacement so&nbsp;if for example&nbsp;<code>s[left..right] = &quot;aaa&quot;</code>, and <code>k = 2</code>, we can only replace two of the letters.&nbsp; (Also, note that the initial string <code>s</code>&nbsp;is never modified by any query.)</p>
23+
24+
<p>&nbsp;</p>
25+
<p><strong>Example :</strong></p>
26+
27+
<pre>
28+
<strong>Input:</strong> s = &quot;abcda&quot;, queries = [[3,3,0],[1,2,0],[0,3,1],[0,3,2],[0,4,1]]
29+
<strong>Output:</strong> [true,false,false,true,true]
30+
<strong>Explanation:</strong>
31+
queries[0] : substring = &quot;d&quot;, is palidrome.
32+
queries[1] :&nbsp;substring = &quot;bc&quot;, is not palidrome.
33+
queries[2] :&nbsp;substring = &quot;abcd&quot;, is not palidrome after replacing only 1 character.
34+
queries[3] :&nbsp;substring = &quot;abcd&quot;, could be changed to &quot;abba&quot; which is palidrome. Also this can be changed to &quot;baab&quot; first rearrange it &quot;bacd&quot; then replace &quot;cd&quot; with &quot;ab&quot;.
35+
queries[4] :&nbsp;substring = &quot;abcda&quot;,&nbsp;could be changed to &quot;abcba&quot; which is palidrome.
36+
</pre>
37+
38+
<p>&nbsp;</p>
39+
<p><strong>Constraints:</strong></p>
40+
41+
<ul>
42+
<li><code>1 &lt;= s.length,&nbsp;queries.length&nbsp;&lt;= 10^5</code></li>
43+
<li><code>0 &lt;= queries[i][0] &lt;= queries[i][1] &lt;&nbsp;s.length</code></li>
44+
<li><code>0 &lt;= queries[i][2] &lt;= s.length</code></li>
45+
<li><code>s</code> only contains lowercase English letters.</li>
46+
</ul>
47+
48+
### Related Topics
49+
[[Array](https://github.com/openset/leetcode/tree/master/tag/array/README.md)]
50+
[[String](https://github.com/openset/leetcode/tree/master/tag/string/README.md)]
51+
52+
### Hints
53+
<details>
54+
<summary>Hint 1</summary>
55+
Since we can rearrange the substring, all we care about is the frequency of each character in that substring.
56+
</details>
57+
58+
<details>
59+
<summary>Hint 2</summary>
60+
How to find the character frequencies efficiently ?
61+
</details>
62+
63+
<details>
64+
<summary>Hint 3</summary>
65+
As a preprocess, calculate the accumulate frequency of all characters for all prefixes of the string.
66+
</details>
67+
68+
<details>
69+
<summary>Hint 4</summary>
70+
How to check if a substring can be changed to a palindrome given its characters frequency ?
71+
</details>
72+
73+
<details>
74+
<summary>Hint 5</summary>
75+
Count the number of odd frequencies, there can be at most one odd frequency in a palindrome.
76+
</details>

Diff for: problems/construct-binary-tree-from-inorder-and-postorder-traversal/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ postorder = [9,15,7,20,3]</pre>
3333
</pre>
3434

3535
### Related Topics
36+
[[Array](https://github.com/openset/leetcode/tree/master/tag/array/README.md)]
3637
[[Tree](https://github.com/openset/leetcode/tree/master/tag/tree/README.md)]
3738
[[Depth-first Search](https://github.com/openset/leetcode/tree/master/tag/depth-first-search/README.md)]
38-
[[Array](https://github.com/openset/leetcode/tree/master/tag/array/README.md)]
3939

4040
### Similar Questions
4141
1. [Construct Binary Tree from Preorder and Inorder Traversal](https://github.com/openset/leetcode/tree/master/problems/construct-binary-tree-from-preorder-and-inorder-traversal) (Medium)

Diff for: problems/construct-binary-tree-from-preorder-and-inorder-traversal/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ inorder = [9,3,15,20,7]</pre>
3232
15 7</pre>
3333

3434
### Related Topics
35+
[[Array](https://github.com/openset/leetcode/tree/master/tag/array/README.md)]
3536
[[Tree](https://github.com/openset/leetcode/tree/master/tag/tree/README.md)]
3637
[[Depth-first Search](https://github.com/openset/leetcode/tree/master/tag/depth-first-search/README.md)]
37-
[[Array](https://github.com/openset/leetcode/tree/master/tag/array/README.md)]
3838

3939
### Similar Questions
4040
1. [Construct Binary Tree from Inorder and Postorder Traversal](https://github.com/openset/leetcode/tree/master/problems/construct-binary-tree-from-inorder-and-postorder-traversal) (Medium)

Diff for: problems/convert-sorted-list-to-binary-search-tree/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ One possible answer is: [0,-3,9,-10,null,5], which represents the following heig
3030
</pre>
3131

3232
### Related Topics
33-
[[Depth-first Search](https://github.com/openset/leetcode/tree/master/tag/depth-first-search/README.md)]
3433
[[Linked List](https://github.com/openset/leetcode/tree/master/tag/linked-list/README.md)]
34+
[[Depth-first Search](https://github.com/openset/leetcode/tree/master/tag/depth-first-search/README.md)]
3535

3636
### Similar Questions
3737
1. [Convert Sorted Array to Binary Search Tree](https://github.com/openset/leetcode/tree/master/problems/convert-sorted-array-to-binary-search-tree) (Easy)

Diff for: problems/design-file-system/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414

1515

1616
### Related Topics
17-
[[Hash Table](https://github.com/openset/leetcode/tree/master/tag/hash-table/README.md)]
1817
[[Design](https://github.com/openset/leetcode/tree/master/tag/design/README.md)]
18+
[[Hash Table](https://github.com/openset/leetcode/tree/master/tag/hash-table/README.md)]
1919

2020
### Hints
2121
<details>

Diff for: problems/diet-plan-performance/README.md

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<!--|This file generated by command(leetcode description); DO NOT EDIT. |-->
2+
<!--+----------------------------------------------------------------------+-->
3+
<!--|@author Openset <[email protected]> |-->
4+
<!--|@link https://github.com/openset |-->
5+
<!--|@home https://github.com/openset/leetcode |-->
6+
<!--+----------------------------------------------------------------------+-->
7+
8+
[< Previous](https://github.com/openset/leetcode/tree/master/problems/prime-arrangements "Prime Arrangements")
9+
                
10+
[Next >](https://github.com/openset/leetcode/tree/master/problems/can-make-palindrome-from-substring "Can Make Palindrome from Substring")
11+
12+
## 5174. Diet Plan Performance (Easy)
13+
14+
<p>A dieter consumes&nbsp;<code>calories[i]</code>&nbsp;calories on the <code>i</code>-th day.&nbsp; For every consecutive sequence of <code>k</code> days, they look at <em>T</em>, the total calories consumed during that sequence of <code>k</code> days:</p>
15+
16+
<ul>
17+
<li>If <code>T &lt; lower</code>, they performed poorly on their diet and lose 1 point;&nbsp;</li>
18+
<li>If <code>T &gt; upper</code>, they performed well on their diet and gain 1 point;</li>
19+
<li>Otherwise, they performed normally and there is no change in points.</li>
20+
</ul>
21+
22+
<p>Return the total number of points the dieter has after all <code>calories.length</code>&nbsp;days.</p>
23+
24+
<p>Note that: The total points could be negative.</p>
25+
26+
<p>&nbsp;</p>
27+
<p><strong>Example 1:</strong></p>
28+
29+
<pre>
30+
<strong>Input:</strong> calories = [1,2,3,4,5], k = 1, lower = 3, upper = 3
31+
<strong>Output:</strong> 0
32+
<strong>Explaination</strong>: calories[0], calories[1] &lt; lower and calories[3], calories[4] &gt; upper, total points = 0.</pre>
33+
34+
<p><strong>Example 2:</strong></p>
35+
36+
<pre>
37+
<strong>Input:</strong> calories = [3,2], k = 2, lower = 0, upper = 1
38+
<strong>Output:</strong> 1
39+
<strong>Explaination</strong>: calories[0] + calories[1] &gt; upper, total points = 1.
40+
</pre>
41+
42+
<p><strong>Example 3:</strong></p>
43+
44+
<pre>
45+
<strong>Input:</strong> calories = [6,5,0,0], k = 2, lower = 1, upper = 5
46+
<strong>Output:</strong> 0
47+
<strong>Explaination</strong>: calories[0] + calories[1] &gt; upper, calories[2] + calories[3] &lt; lower, total points = 0.
48+
</pre>
49+
50+
<p>&nbsp;</p>
51+
<p><strong>Constraints:</strong></p>
52+
53+
<ul>
54+
<li><code>1 &lt;= k &lt;= calories.length &lt;= 10^5</code></li>
55+
<li><code>0 &lt;= calories[i] &lt;= 20000</code></li>
56+
<li><code>0 &lt;= lower &lt;= upper</code></li>
57+
</ul>
58+
59+
### Related Topics
60+
[[Array](https://github.com/openset/leetcode/tree/master/tag/array/README.md)]
61+
[[Sliding Window](https://github.com/openset/leetcode/tree/master/tag/sliding-window/README.md)]
62+
63+
### Hints
64+
<details>
65+
<summary>Hint 1</summary>
66+
Use sliding window technique (aka two pointers).
67+
</details>

Diff for: problems/dinner-plate-stacks/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
[< Previous](https://github.com/openset/leetcode/tree/master/problems/remove-zero-sum-consecutive-nodes-from-linked-list "Remove Zero Sum Consecutive Nodes from Linked List")
99

10-
Next >
10+
[Next >](https://github.com/openset/leetcode/tree/master/problems/immediate-food-delivery-i "Immediate Food Delivery I")
1111

1212
## 1172. Dinner Plate Stacks (Hard)
1313

Diff for: problems/immediate-food-delivery-i/README.md

+14
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 <[email protected]> |-->
4+
<!--|@link https://github.com/openset |-->
5+
<!--|@home https://github.com/openset/leetcode |-->
6+
<!--+----------------------------------------------------------------------+-->
7+
8+
[< Previous](https://github.com/openset/leetcode/tree/master/problems/dinner-plate-stacks "Dinner Plate Stacks")
9+
                
10+
[Next >](https://github.com/openset/leetcode/tree/master/problems/immediate-food-delivery-ii "Immediate Food Delivery II")
11+
12+
## 1173. Immediate Food Delivery I (Easy)
13+
14+

Diff for: problems/immediate-food-delivery-i/mysql_schemas.sql

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Create table If Not Exists Delivery (delivery_id int, customer_id int, order_date date, customer_pref_delivery_date date);
2+
Truncate table Delivery;
3+
insert into Delivery (delivery_id, customer_id, order_date, customer_pref_delivery_date) values ('1', '1', '2019-08-01', '2019-08-02');
4+
insert into Delivery (delivery_id, customer_id, order_date, customer_pref_delivery_date) values ('2', '5', '2019-08-02', '2019-08-02');
5+
insert into Delivery (delivery_id, customer_id, order_date, customer_pref_delivery_date) values ('3', '1', '2019-08-11', '2019-08-11');
6+
insert into Delivery (delivery_id, customer_id, order_date, customer_pref_delivery_date) values ('4', '3', '2019-08-24', '2019-08-26');
7+
insert into Delivery (delivery_id, customer_id, order_date, customer_pref_delivery_date) values ('5', '4', '2019-08-21', '2019-08-22');
8+
insert into Delivery (delivery_id, customer_id, order_date, customer_pref_delivery_date) values ('6', '2', '2019-08-11', '2019-08-13');

Diff for: problems/immediate-food-delivery-ii/README.md

+14
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 <[email protected]> |-->
4+
<!--|@link https://github.com/openset |-->
5+
<!--|@home https://github.com/openset/leetcode |-->
6+
<!--+----------------------------------------------------------------------+-->
7+
8+
[< Previous](https://github.com/openset/leetcode/tree/master/problems/immediate-food-delivery-i "Immediate Food Delivery I")
9+
                
10+
[Next >](https://github.com/openset/leetcode/tree/master/problems/prime-arrangements "Prime Arrangements")
11+
12+
## 1174. Immediate Food Delivery II (Medium)
13+
14+
+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
Create table If Not Exists Delivery (delivery_id int, customer_id int, order_date date, customer_pref_delivery_date date);
2+
Truncate table Delivery;
3+
insert into Delivery (delivery_id, customer_id, order_date, customer_pref_delivery_date) values ('1', '1', '2019-08-01', '2019-08-02');
4+
insert into Delivery (delivery_id, customer_id, order_date, customer_pref_delivery_date) values ('2', '2', '2019-08-02', '2019-08-02');
5+
insert into Delivery (delivery_id, customer_id, order_date, customer_pref_delivery_date) values ('3', '1', '2019-08-11', '2019-08-12');
6+
insert into Delivery (delivery_id, customer_id, order_date, customer_pref_delivery_date) values ('4', '3', '2019-08-24', '2019-08-24');
7+
insert into Delivery (delivery_id, customer_id, order_date, customer_pref_delivery_date) values ('5', '3', '2019-08-21', '2019-08-22');
8+
insert into Delivery (delivery_id, customer_id, order_date, customer_pref_delivery_date) values ('6', '2', '2019-08-11', '2019-08-13');
9+
insert into Delivery (delivery_id, customer_id, order_date, customer_pref_delivery_date) values ('7', '4', '2019-08-09', '2019-08-09');

Diff for: problems/is-subsequence/README.md

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

1010
[Next >](https://github.com/openset/leetcode/tree/master/problems/utf-8-validation "UTF-8 Validation")
1111

12-
## 392. Is Subsequence (Medium)
12+
## 392. Is Subsequence (Easy)
1313

1414
<p>
1515
Given a string <b>s</b> and a string <b>t</b>, check if <b>s</b> is subsequence of <b>t</b>.

Diff for: problems/longest-consecutive-sequence/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
</pre>
2525

2626
### Related Topics
27-
[[Union Find](https://github.com/openset/leetcode/tree/master/tag/union-find/README.md)]
2827
[[Array](https://github.com/openset/leetcode/tree/master/tag/array/README.md)]
28+
[[Union Find](https://github.com/openset/leetcode/tree/master/tag/union-find/README.md)]
2929

3030
### Similar Questions
3131
1. [Binary Tree Longest Consecutive Sequence](https://github.com/openset/leetcode/tree/master/problems/binary-tree-longest-consecutive-sequence) (Medium)

Diff for: problems/number-of-matching-subsequences/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,4 @@ words = [&quot;a&quot;, &quot;bb&quot;, &quot;acd&quot;, &quot;ace&quot;]
3535
[[Array](https://github.com/openset/leetcode/tree/master/tag/array/README.md)]
3636

3737
### Similar Questions
38-
1. [Is Subsequence](https://github.com/openset/leetcode/tree/master/problems/is-subsequence) (Medium)
38+
1. [Is Subsequence](https://github.com/openset/leetcode/tree/master/problems/is-subsequence) (Easy)

0 commit comments

Comments
 (0)