Skip to content

Add: new #628

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,16 @@ LeetCode Problems' Solutions

| # | Title | Solution | Difficulty |
| :-: | - | - | :-: |
| <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 |
| <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 |
| <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 |
| <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 |
| <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 |
| <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 |
| <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 |
| <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 |
| <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 |
| <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 |
| <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 |
| <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 |
| <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 |
| <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 |
Expand Down
2 changes: 1 addition & 1 deletion problems/best-time-to-buy-and-sell-stock-ii/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@
<strong>Explanation:</strong> In this case, no transaction is done, i.e. max profit = 0.</pre>

### Related Topics
[[Greedy](https://github.com/openset/leetcode/tree/master/tag/greedy/README.md)]
[[Array](https://github.com/openset/leetcode/tree/master/tag/array/README.md)]
[[Greedy](https://github.com/openset/leetcode/tree/master/tag/greedy/README.md)]

### Similar Questions
1. [Best Time to Buy and Sell Stock](https://github.com/openset/leetcode/tree/master/problems/best-time-to-buy-and-sell-stock) (Easy)
Expand Down
76 changes: 76 additions & 0 deletions problems/can-make-palindrome-from-substring/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<!--|This file generated by command(leetcode description); DO NOT EDIT. |-->
<!--+----------------------------------------------------------------------+-->
<!--|@author Openset <[email protected]> |-->
<!--|@link https://github.com/openset |-->
<!--|@home https://github.com/openset/leetcode |-->
<!--+----------------------------------------------------------------------+-->

[< Previous](https://github.com/openset/leetcode/tree/master/problems/diet-plan-performance "Diet Plan Performance")

[Next >](https://github.com/openset/leetcode/tree/master/problems/number-of-valid-words-for-each-puzzle "Number of Valid Words for Each Puzzle")

## 5175. Can Make Palindrome from Substring (Medium)

<p>Given a string <code>s</code>, we make queries on substrings of <code>s</code>.</p>

<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>

<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>

<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>

<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>

<p>&nbsp;</p>
<p><strong>Example :</strong></p>

<pre>
<strong>Input:</strong> s = &quot;abcda&quot;, queries = [[3,3,0],[1,2,0],[0,3,1],[0,3,2],[0,4,1]]
<strong>Output:</strong> [true,false,false,true,true]
<strong>Explanation:</strong>
queries[0] : substring = &quot;d&quot;, is palidrome.
queries[1] :&nbsp;substring = &quot;bc&quot;, is not palidrome.
queries[2] :&nbsp;substring = &quot;abcd&quot;, is not palidrome after replacing only 1 character.
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;.
queries[4] :&nbsp;substring = &quot;abcda&quot;,&nbsp;could be changed to &quot;abcba&quot; which is palidrome.
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
<li><code>1 &lt;= s.length,&nbsp;queries.length&nbsp;&lt;= 10^5</code></li>
<li><code>0 &lt;= queries[i][0] &lt;= queries[i][1] &lt;&nbsp;s.length</code></li>
<li><code>0 &lt;= queries[i][2] &lt;= s.length</code></li>
<li><code>s</code> only contains lowercase English letters.</li>
</ul>

### Related Topics
[[Array](https://github.com/openset/leetcode/tree/master/tag/array/README.md)]
[[String](https://github.com/openset/leetcode/tree/master/tag/string/README.md)]

### Hints
<details>
<summary>Hint 1</summary>
Since we can rearrange the substring, all we care about is the frequency of each character in that substring.
</details>

<details>
<summary>Hint 2</summary>
How to find the character frequencies efficiently ?
</details>

<details>
<summary>Hint 3</summary>
As a preprocess, calculate the accumulate frequency of all characters for all prefixes of the string.
</details>

<details>
<summary>Hint 4</summary>
How to check if a substring can be changed to a palindrome given its characters frequency ?
</details>

<details>
<summary>Hint 5</summary>
Count the number of odd frequencies, there can be at most one odd frequency in a palindrome.
</details>
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ postorder = [9,15,7,20,3]</pre>
</pre>

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

### Similar Questions
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)
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ inorder = [9,3,15,20,7]</pre>
15 7</pre>

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

### Similar Questions
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)
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ One possible answer is: [0,-3,9,-10,null,5], which represents the following heig
</pre>

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

### Similar Questions
1. [Convert Sorted Array to Binary Search Tree](https://github.com/openset/leetcode/tree/master/problems/convert-sorted-array-to-binary-search-tree) (Easy)
2 changes: 1 addition & 1 deletion problems/design-file-system/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@


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

### Hints
<details>
Expand Down
67 changes: 67 additions & 0 deletions problems/diet-plan-performance/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<!--|This file generated by command(leetcode description); DO NOT EDIT. |-->
<!--+----------------------------------------------------------------------+-->
<!--|@author Openset <[email protected]> |-->
<!--|@link https://github.com/openset |-->
<!--|@home https://github.com/openset/leetcode |-->
<!--+----------------------------------------------------------------------+-->

[< Previous](https://github.com/openset/leetcode/tree/master/problems/prime-arrangements "Prime Arrangements")

[Next >](https://github.com/openset/leetcode/tree/master/problems/can-make-palindrome-from-substring "Can Make Palindrome from Substring")

## 5174. Diet Plan Performance (Easy)

<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>

<ul>
<li>If <code>T &lt; lower</code>, they performed poorly on their diet and lose 1 point;&nbsp;</li>
<li>If <code>T &gt; upper</code>, they performed well on their diet and gain 1 point;</li>
<li>Otherwise, they performed normally and there is no change in points.</li>
</ul>

<p>Return the total number of points the dieter has after all <code>calories.length</code>&nbsp;days.</p>

<p>Note that: The total points could be negative.</p>

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

<pre>
<strong>Input:</strong> calories = [1,2,3,4,5], k = 1, lower = 3, upper = 3
<strong>Output:</strong> 0
<strong>Explaination</strong>: calories[0], calories[1] &lt; lower and calories[3], calories[4] &gt; upper, total points = 0.</pre>

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

<pre>
<strong>Input:</strong> calories = [3,2], k = 2, lower = 0, upper = 1
<strong>Output:</strong> 1
<strong>Explaination</strong>: calories[0] + calories[1] &gt; upper, total points = 1.
</pre>

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

<pre>
<strong>Input:</strong> calories = [6,5,0,0], k = 2, lower = 1, upper = 5
<strong>Output:</strong> 0
<strong>Explaination</strong>: calories[0] + calories[1] &gt; upper, calories[2] + calories[3] &lt; lower, total points = 0.
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
<li><code>1 &lt;= k &lt;= calories.length &lt;= 10^5</code></li>
<li><code>0 &lt;= calories[i] &lt;= 20000</code></li>
<li><code>0 &lt;= lower &lt;= upper</code></li>
</ul>

### Related Topics
[[Array](https://github.com/openset/leetcode/tree/master/tag/array/README.md)]
[[Sliding Window](https://github.com/openset/leetcode/tree/master/tag/sliding-window/README.md)]

### Hints
<details>
<summary>Hint 1</summary>
Use sliding window technique (aka two pointers).
</details>
2 changes: 1 addition & 1 deletion problems/dinner-plate-stacks/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

[< 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")

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

## 1172. Dinner Plate Stacks (Hard)

Expand Down
14 changes: 14 additions & 0 deletions problems/immediate-food-delivery-i/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!--|This file generated by command(leetcode description); DO NOT EDIT. |-->
<!--+----------------------------------------------------------------------+-->
<!--|@author Openset <[email protected]> |-->
<!--|@link https://github.com/openset |-->
<!--|@home https://github.com/openset/leetcode |-->
<!--+----------------------------------------------------------------------+-->

[< Previous](https://github.com/openset/leetcode/tree/master/problems/dinner-plate-stacks "Dinner Plate Stacks")

[Next >](https://github.com/openset/leetcode/tree/master/problems/immediate-food-delivery-ii "Immediate Food Delivery II")

## 1173. Immediate Food Delivery I (Easy)


8 changes: 8 additions & 0 deletions problems/immediate-food-delivery-i/mysql_schemas.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Create table If Not Exists Delivery (delivery_id int, customer_id int, order_date date, customer_pref_delivery_date date);
Truncate table Delivery;
insert into Delivery (delivery_id, customer_id, order_date, customer_pref_delivery_date) values ('1', '1', '2019-08-01', '2019-08-02');
insert into Delivery (delivery_id, customer_id, order_date, customer_pref_delivery_date) values ('2', '5', '2019-08-02', '2019-08-02');
insert into Delivery (delivery_id, customer_id, order_date, customer_pref_delivery_date) values ('3', '1', '2019-08-11', '2019-08-11');
insert into Delivery (delivery_id, customer_id, order_date, customer_pref_delivery_date) values ('4', '3', '2019-08-24', '2019-08-26');
insert into Delivery (delivery_id, customer_id, order_date, customer_pref_delivery_date) values ('5', '4', '2019-08-21', '2019-08-22');
insert into Delivery (delivery_id, customer_id, order_date, customer_pref_delivery_date) values ('6', '2', '2019-08-11', '2019-08-13');
14 changes: 14 additions & 0 deletions problems/immediate-food-delivery-ii/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!--|This file generated by command(leetcode description); DO NOT EDIT. |-->
<!--+----------------------------------------------------------------------+-->
<!--|@author Openset <[email protected]> |-->
<!--|@link https://github.com/openset |-->
<!--|@home https://github.com/openset/leetcode |-->
<!--+----------------------------------------------------------------------+-->

[< Previous](https://github.com/openset/leetcode/tree/master/problems/immediate-food-delivery-i "Immediate Food Delivery I")

[Next >](https://github.com/openset/leetcode/tree/master/problems/prime-arrangements "Prime Arrangements")

## 1174. Immediate Food Delivery II (Medium)


9 changes: 9 additions & 0 deletions problems/immediate-food-delivery-ii/mysql_schemas.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Create table If Not Exists Delivery (delivery_id int, customer_id int, order_date date, customer_pref_delivery_date date);
Truncate table Delivery;
insert into Delivery (delivery_id, customer_id, order_date, customer_pref_delivery_date) values ('1', '1', '2019-08-01', '2019-08-02');
insert into Delivery (delivery_id, customer_id, order_date, customer_pref_delivery_date) values ('2', '2', '2019-08-02', '2019-08-02');
insert into Delivery (delivery_id, customer_id, order_date, customer_pref_delivery_date) values ('3', '1', '2019-08-11', '2019-08-12');
insert into Delivery (delivery_id, customer_id, order_date, customer_pref_delivery_date) values ('4', '3', '2019-08-24', '2019-08-24');
insert into Delivery (delivery_id, customer_id, order_date, customer_pref_delivery_date) values ('5', '3', '2019-08-21', '2019-08-22');
insert into Delivery (delivery_id, customer_id, order_date, customer_pref_delivery_date) values ('6', '2', '2019-08-11', '2019-08-13');
insert into Delivery (delivery_id, customer_id, order_date, customer_pref_delivery_date) values ('7', '4', '2019-08-09', '2019-08-09');
2 changes: 1 addition & 1 deletion problems/is-subsequence/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

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

## 392. Is Subsequence (Medium)
## 392. Is Subsequence (Easy)

<p>
Given a string <b>s</b> and a string <b>t</b>, check if <b>s</b> is subsequence of <b>t</b>.
Expand Down
2 changes: 1 addition & 1 deletion problems/longest-consecutive-sequence/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
</pre>

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

### Similar Questions
1. [Binary Tree Longest Consecutive Sequence](https://github.com/openset/leetcode/tree/master/problems/binary-tree-longest-consecutive-sequence) (Medium)
2 changes: 1 addition & 1 deletion problems/number-of-matching-subsequences/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@ words = [&quot;a&quot;, &quot;bb&quot;, &quot;acd&quot;, &quot;ace&quot;]
[[Array](https://github.com/openset/leetcode/tree/master/tag/array/README.md)]

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