Skip to content

Commit 2bf8062

Browse files
author
Shuo
authored
Merge pull request #762 from openset/develop
Add: new
2 parents 2f43eb8 + a69f341 commit 2bf8062

File tree

37 files changed

+1397
-38
lines changed

37 files changed

+1397
-38
lines changed

README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,25 @@ LeetCode Problems' Solutions
6262

6363
| # | Title | Solution | Difficulty |
6464
| :-: | - | - | :-: |
65+
| <span id="1340">1340</span> | [Jump Game V](https://leetcode.com/problems/jump-game-v "跳跃游戏 V") | [Go](problems/jump-game-v) | Hard |
66+
| <span id="1339">1339</span> | [Maximum Product of Splitted Binary Tree](https://leetcode.com/problems/maximum-product-of-splitted-binary-tree "分裂二叉树的最大乘积") | [Go](problems/maximum-product-of-splitted-binary-tree) | Medium |
67+
| <span id="1338">1338</span> | [Reduce Array Size to The Half](https://leetcode.com/problems/reduce-array-size-to-the-half "数组大小减半") | [Go](problems/reduce-array-size-to-the-half) | Medium |
68+
| <span id="1337">1337</span> | [The K Weakest Rows in a Matrix](https://leetcode.com/problems/the-k-weakest-rows-in-a-matrix "方阵中战斗力最弱的 K 行") | [Go](problems/the-k-weakest-rows-in-a-matrix) | Easy |
69+
| <span id="1336">1336</span> | [Number of Transactions per Visit](https://leetcode.com/problems/number-of-transactions-per-visit) 🔒 | [MySQL](problems/number-of-transactions-per-visit) | Medium |
70+
| <span id="1335">1335</span> | [Minimum Difficulty of a Job Schedule](https://leetcode.com/problems/minimum-difficulty-of-a-job-schedule "工作计划的最低难度") | [Go](problems/minimum-difficulty-of-a-job-schedule) | Hard |
71+
| <span id="1334">1334</span> | [Find the City With the Smallest Number of Neighbors at a Threshold Distance](https://leetcode.com/problems/find-the-city-with-the-smallest-number-of-neighbors-at-a-threshold-distance "阈值距离内邻居最少的城市") | [Go](problems/find-the-city-with-the-smallest-number-of-neighbors-at-a-threshold-distance) | Medium |
72+
| <span id="1333">1333</span> | [Filter Restaurants by Vegan-Friendly, Price and Distance](https://leetcode.com/problems/filter-restaurants-by-vegan-friendly-price-and-distance "餐厅过滤器") | [Go](problems/filter-restaurants-by-vegan-friendly-price-and-distance) | Medium |
73+
| <span id="1332">1332</span> | [Remove Palindromic Subsequences](https://leetcode.com/problems/remove-palindromic-subsequences "删除回文子序列") | [Go](problems/remove-palindromic-subsequences) | Easy |
74+
| <span id="1331">1331</span> | [Rank Transform of an Array](https://leetcode.com/problems/rank-transform-of-an-array "数组序号转换") | [Go](problems/rank-transform-of-an-array) | Easy |
75+
| <span id="1330">1330</span> | [Reverse Subarray To Maximize Array Value](https://leetcode.com/problems/reverse-subarray-to-maximize-array-value "翻转子数组得到最大的数组值") | [Go](problems/reverse-subarray-to-maximize-array-value) | Hard |
76+
| <span id="1329">1329</span> | [Sort the Matrix Diagonally](https://leetcode.com/problems/sort-the-matrix-diagonally "将矩阵按对角线排序") | [Go](problems/sort-the-matrix-diagonally) | Medium |
77+
| <span id="1328">1328</span> | [Break a Palindrome](https://leetcode.com/problems/break-a-palindrome "破坏回文串") | [Go](problems/break-a-palindrome) | Medium |
78+
| <span id="1327">1327</span> | [List the Products Ordered in a Period](https://leetcode.com/problems/list-the-products-ordered-in-a-period) 🔒 | [MySQL](problems/list-the-products-ordered-in-a-period) | Easy |
79+
| <span id="1326">1326</span> | [Minimum Number of Taps to Open to Water a Garden](https://leetcode.com/problems/minimum-number-of-taps-to-open-to-water-a-garden "灌溉花园的最少水龙头数目") | [Go](problems/minimum-number-of-taps-to-open-to-water-a-garden) | Hard |
80+
| <span id="1325">1325</span> | [Delete Leaves With a Given Value](https://leetcode.com/problems/delete-leaves-with-a-given-value "删除给定值的叶子节点") | [Go](problems/delete-leaves-with-a-given-value) | Medium |
81+
| <span id="1324">1324</span> | [Print Words Vertically](https://leetcode.com/problems/print-words-vertically "竖直打印单词") | [Go](problems/print-words-vertically) | Medium |
82+
| <span id="1323">1323</span> | [Maximum 69 Number](https://leetcode.com/problems/maximum-69-number "6 和 9 组成的最大数字") | [Go](problems/maximum-69-number) | Easy |
83+
| <span id="1322">1322</span> | [Ads Performance](https://leetcode.com/problems/ads-performance) 🔒 | [MySQL](problems/ads-performance) | Easy |
6584
| <span id="1321">1321</span> | [Restaurant Growth](https://leetcode.com/problems/restaurant-growth) 🔒 | [MySQL](problems/restaurant-growth) | Medium |
6685
| <span id="1320">1320</span> | [Minimum Distance to Type a Word Using Two Fingers](https://leetcode.com/problems/minimum-distance-to-type-a-word-using-two-fingers "二指输入的的最小距离") | [Go](problems/minimum-distance-to-type-a-word-using-two-fingers) | Hard |
6786
| <span id="1319">1319</span> | [Number of Operations to Make Network Connected](https://leetcode.com/problems/number-of-operations-to-make-network-connected "连通网络的操作次数") | [Go](problems/number-of-operations-to-make-network-connected) | Medium |

problems/ads-performance/README.md

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](../restaurant-growth "Restaurant Growth")
9+
                
10+
[Next >](../maximum-69-number "Maximum 69 Number")
11+
12+
## [1322. Ads Performance (Easy)](https://leetcode.com/problems/ads-performance "")
13+
14+
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
Create table If Not Exists Ads (ad_id int, user_id int, action ENUM('Clicked', 'Viewed', 'Ignored'));
2+
Truncate table Ads;
3+
insert into Ads (ad_id, user_id, action) values ('1', '1', 'Clicked');
4+
insert into Ads (ad_id, user_id, action) values ('2', '2', 'Clicked');
5+
insert into Ads (ad_id, user_id, action) values ('3', '3', 'Viewed');
6+
insert into Ads (ad_id, user_id, action) values ('5', '5', 'Ignored');
7+
insert into Ads (ad_id, user_id, action) values ('1', '7', 'Ignored');
8+
insert into Ads (ad_id, user_id, action) values ('2', '7', 'Viewed');
9+
insert into Ads (ad_id, user_id, action) values ('3', '5', 'Clicked');
10+
insert into Ads (ad_id, user_id, action) values ('1', '4', 'Viewed');
11+
insert into Ads (ad_id, user_id, action) values ('2', '11', 'Viewed');
12+
insert into Ads (ad_id, user_id, action) values ('1', '2', 'Clicked');

problems/break-a-palindrome/README.md

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
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](../list-the-products-ordered-in-a-period "List the Products Ordered in a Period")
9+
                
10+
[Next >](../sort-the-matrix-diagonally "Sort the Matrix Diagonally")
11+
12+
## [1328. Break a Palindrome (Medium)](https://leetcode.com/problems/break-a-palindrome "破坏回文串")
13+
14+
<p>Given a palindromic string <code>palindrome</code>, replace <strong>exactly one</strong> character by any lowercase English letter so that the string becomes the lexicographically smallest possible string that <strong>isn&#39;t</strong> a palindrome.</p>
15+
16+
<p>After doing so, return the final string.&nbsp; If there is no way to do so, return the empty string.</p>
17+
18+
<p>&nbsp;</p>
19+
<p><strong>Example 1:</strong></p>
20+
21+
<pre>
22+
<strong>Input:</strong> palindrome = &quot;abccba&quot;
23+
<strong>Output:</strong> &quot;aaccba&quot;
24+
</pre>
25+
26+
<p><strong>Example 2:</strong></p>
27+
28+
<pre>
29+
<strong>Input:</strong> palindrome = &quot;a&quot;
30+
<strong>Output:</strong> &quot;&quot;
31+
</pre>
32+
33+
<p>&nbsp;</p>
34+
<p><strong>Constraints:</strong></p>
35+
36+
<ul>
37+
<li><code>1 &lt;= palindrome.length &lt;= 1000</code></li>
38+
<li><code>palindrome</code>&nbsp;consists of only lowercase English letters.</li>
39+
</ul>
40+
41+
### Related Topics
42+
[[String](../../tag/string/README.md)]
43+
44+
### Hints
45+
<details>
46+
<summary>Hint 1</summary>
47+
How to detect if there is impossible to perform the replacement? Only when the length = 1.
48+
</details>
49+
50+
<details>
51+
<summary>Hint 2</summary>
52+
Change the first non 'a' character to 'a'.
53+
</details>
54+
55+
<details>
56+
<summary>Hint 3</summary>
57+
What if the string has only 'a'?
58+
</details>
59+
60+
<details>
61+
<summary>Hint 4</summary>
62+
Change the last character to 'b'.
63+
</details>
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
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](../print-words-vertically "Print Words Vertically")
9+
                
10+
[Next >](../minimum-number-of-taps-to-open-to-water-a-garden "Minimum Number of Taps to Open to Water a Garden")
11+
12+
## [1325. Delete Leaves With a Given Value (Medium)](https://leetcode.com/problems/delete-leaves-with-a-given-value "删除给定值的叶子节点")
13+
14+
<p>Given a binary tree&nbsp;<code>root</code>&nbsp;and an integer&nbsp;<code>target</code>, delete all the&nbsp;<strong>leaf nodes</strong>&nbsp;with value <code>target</code>.</p>
15+
16+
<p>Note&nbsp;that once you delete a leaf node with value <code>target</code><strong>,&nbsp;</strong>if it&#39;s parent node becomes a leaf node and has the value <code><font face="monospace">target</font></code>, it should also be deleted (you need to continue doing that until you can&#39;t).</p>
17+
18+
<p>&nbsp;</p>
19+
<p><strong>Example 1:</strong></p>
20+
21+
<p><strong><img alt="" src="https://assets.leetcode.com/uploads/2020/01/09/sample_1_1684.png" style="width: 550px; height: 120px;" /></strong></p>
22+
23+
<pre>
24+
<strong>Input:</strong> root = [1,2,3,2,null,2,4], target = 2
25+
<strong>Output:</strong> [1,null,3,null,4]
26+
<strong>Explanation:</strong> Leaf nodes in green with value (target = 2) are removed (Picture in left).
27+
After removing, new nodes become leaf nodes with value (target = 2) (Picture in center).
28+
</pre>
29+
30+
<p><strong>Example 2:</strong></p>
31+
32+
<p><strong><img alt="" src="https://assets.leetcode.com/uploads/2020/01/09/sample_2_1684.png" style="width: 300px; height: 120px;" /></strong></p>
33+
34+
<pre>
35+
<strong>Input:</strong> root = [1,3,3,3,2], target = 3
36+
<strong>Output:</strong> [1,3,null,null,2]
37+
</pre>
38+
39+
<p><strong>Example 3:</strong></p>
40+
41+
<p><strong><img alt="" src="https://assets.leetcode.com/uploads/2020/01/15/sample_3_1684.png" style="width: 420px; height: 150px;" /></strong></p>
42+
43+
<pre>
44+
<strong>Input:</strong> root = [1,2,null,2,null,2], target = 2
45+
<strong>Output:</strong> [1]
46+
<strong>Explanation:</strong> Leaf nodes in green with value (target = 2) are removed at each step.
47+
</pre>
48+
49+
<p><strong>Example 4:</strong></p>
50+
51+
<pre>
52+
<strong>Input:</strong> root = [1,1,1], target = 1
53+
<strong>Output:</strong> []
54+
</pre>
55+
56+
<p><strong>Example 5:</strong></p>
57+
58+
<pre>
59+
<strong>Input:</strong> root = [1,2,3], target = 1
60+
<strong>Output:</strong> [1,2,3]
61+
</pre>
62+
63+
<p>&nbsp;</p>
64+
<p><strong>Constraints:</strong></p>
65+
66+
<ul>
67+
<li><code>1 &lt;= target&nbsp;&lt;= 1000</code></li>
68+
<li>Each tree has at most <code>3000</code> nodes.</li>
69+
<li>Each node&#39;s value is between <code>[1, 1000]</code>.</li>
70+
</ul>
71+
72+
### Related Topics
73+
[[Tree](../../tag/tree/README.md)]
74+
75+
### Hints
76+
<details>
77+
<summary>Hint 1</summary>
78+
Use the DFS to reconstruct the tree such that no leaf node is equal to the target. If the leaf node is equal to the target, return an empty object instead.
79+
</details>
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
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](../remove-palindromic-subsequences "Remove Palindromic Subsequences")
9+
                
10+
[Next >](../find-the-city-with-the-smallest-number-of-neighbors-at-a-threshold-distance "Find the City With the Smallest Number of Neighbors at a Threshold Distance")
11+
12+
## [1333. Filter Restaurants by Vegan-Friendly, Price and Distance (Medium)](https://leetcode.com/problems/filter-restaurants-by-vegan-friendly-price-and-distance "餐厅过滤器")
13+
14+
<p>Given the array <code>restaurants</code> where &nbsp;<code>restaurants[i] = [id<sub>i</sub>, rating<sub>i</sub>, veganFriendly<sub>i</sub>, price<sub>i</sub>, distance<sub>i</sub>]</code>. You have to filter the restaurants using three filters.</p>
15+
16+
<p>The <code>veganFriendly</code> filter will be either <em>true</em> (meaning you should only include restaurants with <code>veganFriendly<sub>i</sub></code> set to true)&nbsp;or <em>false</em>&nbsp;(meaning you can include any restaurant). In addition, you have the filters&nbsp;<code>maxPrice</code> and <code>maxDistance</code>&nbsp;which&nbsp;are the maximum value for price and distance of restaurants you should consider respectively.</p>
17+
18+
<p>Return the array of restaurant <em><strong>IDs</strong></em> after filtering, ordered by <strong>rating</strong> from highest to lowest. For restaurants with the same rating, order them by <em><strong>id</strong></em> from highest to lowest. For simplicity <code>veganFriendly<sub>i</sub></code> and <code>veganFriendly</code> take value <em>1</em> when it is <em>true</em>, and <em>0</em> when it is <em>false</em>.</p>
19+
20+
<p>&nbsp;</p>
21+
<p><strong>Example 1:</strong></p>
22+
23+
<pre>
24+
<strong>Input:</strong> restaurants = [[1,4,1,40,10],[2,8,0,50,5],[3,8,1,30,4],[4,10,0,10,3],[5,1,1,15,1]], veganFriendly = 1, maxPrice = 50, maxDistance = 10
25+
<strong>Output:</strong> [3,1,5]
26+
<strong>Explanation:
27+
</strong>The restaurants are:
28+
Restaurant 1 [id=1, rating=4, veganFriendly=1, price=40, distance=10]
29+
Restaurant 2 [id=2, rating=8, veganFriendly=0, price=50, distance=5]
30+
Restaurant 3 [id=3, rating=8, veganFriendly=1, price=30, distance=4]
31+
Restaurant 4 [id=4, rating=10, veganFriendly=0, price=10, distance=3]
32+
Restaurant 5 [id=5, rating=1, veganFriendly=1, price=15, distance=1]
33+
After filter restaurants with veganFriendly = 1, maxPrice = 50 and maxDistance = 10 we have restaurant 3, restaurant 1 and restaurant 5 (ordered by rating from highest to lowest).
34+
</pre>
35+
36+
<p><strong>Example 2:</strong></p>
37+
38+
<pre>
39+
<strong>Input:</strong> restaurants = [[1,4,1,40,10],[2,8,0,50,5],[3,8,1,30,4],[4,10,0,10,3],[5,1,1,15,1]], veganFriendly = 0, maxPrice = 50, maxDistance = 10
40+
<strong>Output:</strong> [4,3,2,1,5]
41+
<strong>Explanation:</strong> The restaurants are the same as in example 1, but in this case the filter veganFriendly = 0, therefore all restaurants are considered.
42+
</pre>
43+
44+
<p><strong>Example 3:</strong></p>
45+
46+
<pre>
47+
<strong>Input:</strong> restaurants = [[1,4,1,40,10],[2,8,0,50,5],[3,8,1,30,4],[4,10,0,10,3],[5,1,1,15,1]], veganFriendly = 0, maxPrice = 30, maxDistance = 3
48+
<strong>Output:</strong> [4,5]
49+
</pre>
50+
51+
<p>&nbsp;</p>
52+
<p><strong>Constraints:</strong></p>
53+
54+
<ul>
55+
<li><code>1 &lt;=&nbsp;restaurants.length &lt;= 10^4</code></li>
56+
<li><code>restaurants[i].length == 5</code></li>
57+
<li><code>1 &lt;=&nbsp;id<sub>i</sub>, rating<sub>i</sub>, price<sub>i</sub>, distance<sub>i </sub>&lt;= 10^5</code></li>
58+
<li><code>1 &lt;=&nbsp;maxPrice,&nbsp;maxDistance &lt;= 10^5</code></li>
59+
<li><code>veganFriendly<sub>i</sub></code> and&nbsp;<code>veganFriendly</code>&nbsp;are&nbsp;0 or 1.</li>
60+
<li>All <code>id<sub>i</sub></code> are distinct.</li>
61+
</ul>
62+
63+
### Related Topics
64+
[[Sort](../../tag/sort/README.md)]
65+
[[Array](../../tag/array/README.md)]
66+
67+
### Hints
68+
<details>
69+
<summary>Hint 1</summary>
70+
Do the filtering and sort as said. Note that the id may not be the index in the array.
71+
</details>

0 commit comments

Comments
 (0)