Skip to content

Commit 6676eab

Browse files
author
openset
committed
Add: new
1 parent 037fda7 commit 6676eab

File tree

23 files changed

+540
-2
lines changed

23 files changed

+540
-2
lines changed

README.md

+9
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,15 @@ LeetCode Problems' Solutions
6262

6363
| # | Title | Solution | Difficulty |
6464
| :-: | - | - | :-: |
65+
| <span id="1307">1307</span> | [Verbal Arithmetic Puzzle](https://leetcode.com/problems/verbal-arithmetic-puzzle "口算难题") | [Go](problems/verbal-arithmetic-puzzle) | Hard |
66+
| <span id="1306">1306</span> | [Jump Game III](https://leetcode.com/problems/jump-game-iii "跳跃游戏 III") | [Go](problems/jump-game-iii) | Medium |
67+
| <span id="1305">1305</span> | [All Elements in Two Binary Search Trees](https://leetcode.com/problems/all-elements-in-two-binary-search-trees "两棵二叉搜索树中的所有元素") | [Go](problems/all-elements-in-two-binary-search-trees) | Medium |
68+
| <span id="1304">1304</span> | [Find N Unique Integers Sum up to Zero](https://leetcode.com/problems/find-n-unique-integers-sum-up-to-zero "和为零的N个唯一整数") | [Go](problems/find-n-unique-integers-sum-up-to-zero) | Easy |
69+
| <span id="1303">1303</span> | [Find the Team Size](https://leetcode.com/problems/find-the-team-size) 🔒 | [MySQL](problems/find-the-team-size) | Easy |
70+
| <span id="1302">1302</span> | [Deepest Leaves Sum](https://leetcode.com/problems/deepest-leaves-sum "层数最深叶子节点的和") | [Go](problems/deepest-leaves-sum) | Medium |
71+
| <span id="1301">1301</span> | [Number of Paths with Max Score](https://leetcode.com/problems/number-of-paths-with-max-score "最大得分的路径数目") | [Go](problems/number-of-paths-with-max-score) | Hard |
72+
| <span id="1300">1300</span> | [Sum of Mutated Array Closest to Target](https://leetcode.com/problems/sum-of-mutated-array-closest-to-target "转变数组后最接近目标值的数组和") | [Go](problems/sum-of-mutated-array-closest-to-target) | Medium |
73+
| <span id="1299">1299</span> | [Replace Elements with Greatest Element on Right Side](https://leetcode.com/problems/replace-elements-with-greatest-element-on-right-side "将每个元素替换为右侧最大元素") | [Go](problems/replace-elements-with-greatest-element-on-right-side) | Easy |
6574
| <span id="1298">1298</span> | [Maximum Candies You Can Get from Boxes](https://leetcode.com/problems/maximum-candies-you-can-get-from-boxes "你能从盒子里获得的最大糖果数") | [Go](problems/maximum-candies-you-can-get-from-boxes) | Hard |
6675
| <span id="1297">1297</span> | [Maximum Number of Occurrences of a Substring](https://leetcode.com/problems/maximum-number-of-occurrences-of-a-substring "子串的最大出现次数") | [Go](problems/maximum-number-of-occurrences-of-a-substring) | Medium |
6776
| <span id="1296">1296</span> | [Divide Array in Sets of K Consecutive Numbers](https://leetcode.com/problems/divide-array-in-sets-of-k-consecutive-numbers "划分数组为连续数字的集合") | [Go](problems/divide-array-in-sets-of-k-consecutive-numbers) | Medium |
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 <[email protected]> |-->
4+
<!--|@link https://github.com/openset |-->
5+
<!--|@home https://github.com/openset/leetcode |-->
6+
<!--+----------------------------------------------------------------------+-->
7+
8+
[< Previous](../find-n-unique-integers-sum-up-to-zero "Find N Unique Integers Sum up to Zero")
9+
                
10+
[Next >](../jump-game-iii "Jump Game III")
11+
12+
## [1305. All Elements in Two Binary Search Trees (Medium)](https://leetcode.com/problems/all-elements-in-two-binary-search-trees "两棵二叉搜索树中的所有元素")
13+
14+
<p>Given two binary search trees <code>root1</code> and <code>root2</code>.</p>
15+
16+
<p>Return a list containing <em>all the integers</em> from <em>both trees</em> sorted in <strong>ascending</strong> order.</p>
17+
18+
<p>&nbsp;</p>
19+
<p><strong>Example 1:</strong></p>
20+
<img alt="" src="https://assets.leetcode.com/uploads/2019/12/18/q2-e1.png" style="width: 457px; height: 207px;" />
21+
<pre>
22+
<strong>Input:</strong> root1 = [2,1,4], root2 = [1,0,3]
23+
<strong>Output:</strong> [0,1,1,2,3,4]
24+
</pre>
25+
26+
<p><strong>Example 2:</strong></p>
27+
28+
<pre>
29+
<strong>Input:</strong> root1 = [0,-10,10], root2 = [5,1,7,0,2]
30+
<strong>Output:</strong> [-10,0,0,1,2,5,7,10]
31+
</pre>
32+
33+
<p><strong>Example 3:</strong></p>
34+
35+
<pre>
36+
<strong>Input:</strong> root1 = [], root2 = [5,1,7,0,2]
37+
<strong>Output:</strong> [0,1,2,5,7]
38+
</pre>
39+
40+
<p><strong>Example 4:</strong></p>
41+
42+
<pre>
43+
<strong>Input:</strong> root1 = [0,-10,10], root2 = []
44+
<strong>Output:</strong> [-10,0,10]
45+
</pre>
46+
47+
<p><strong>Example 5:</strong></p>
48+
<img alt="" src="https://assets.leetcode.com/uploads/2019/12/18/q2-e5-.png" style="width: 352px; height: 197px;" />
49+
<pre>
50+
<strong>Input:</strong> root1 = [1,null,8], root2 = [8,1]
51+
<strong>Output:</strong> [1,1,8,8]
52+
</pre>
53+
54+
<p>&nbsp;</p>
55+
<p><strong>Constraints:</strong></p>
56+
57+
<ul>
58+
<li>Each tree has at most <code>5000</code> nodes.</li>
59+
<li>Each node&#39;s value is between <code>[-10^5, 10^5]</code>.</li>
60+
</ul>
61+
62+
### Related Topics
63+
[[Sort](../../tag/sort/README.md)]
64+
[[Tree](../../tag/tree/README.md)]
65+
66+
### Hints
67+
<details>
68+
<summary>Hint 1</summary>
69+
Traverse the first tree in list1 and the second tree in list2.
70+
</details>
71+
72+
<details>
73+
<summary>Hint 2</summary>
74+
Merge the two trees in one list and sort it.
75+
</details>

problems/best-meeting-point/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ Explanation: </strong>Given three people living at <code>(0,0)</code>, <code>(0,
3131
&nbsp; of 2+2+2=6 is minimal. So return 6.</pre>
3232

3333
### Related Topics
34-
[[Math](../../tag/math/README.md)]
3534
[[Sort](../../tag/sort/README.md)]
35+
[[Math](../../tag/math/README.md)]
3636

3737
### Similar Questions
3838
1. [Shortest Distance from All Buildings](../shortest-distance-from-all-buildings) (Hard)

problems/deepest-leaves-sum/README.md

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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](../number-of-paths-with-max-score "Number of Paths with Max Score")
9+
                
10+
[Next >](../find-the-team-size "Find the Team Size")
11+
12+
## [1302. Deepest Leaves Sum (Medium)](https://leetcode.com/problems/deepest-leaves-sum "层数最深叶子节点的和")
13+
14+
Given a binary tree, return the sum of values of its deepest leaves.
15+
<p>&nbsp;</p>
16+
<p><strong>Example 1:</strong></p>
17+
18+
<p><strong><img alt="" src="https://assets.leetcode.com/uploads/2019/07/31/1483_ex1.png" style="width: 273px; height: 265px;" /></strong></p>
19+
20+
<pre>
21+
<strong>Input:</strong> root = [1,2,3,4,5,null,6,7,null,null,null,null,8]
22+
<strong>Output:</strong> 15
23+
</pre>
24+
25+
<p>&nbsp;</p>
26+
<p><strong>Constraints:</strong></p>
27+
28+
<ul>
29+
<li>The number of nodes in the tree is between&nbsp;<code>1</code>&nbsp;and&nbsp;<code>10^4</code>.</li>
30+
<li>The value of nodes is between&nbsp;<code>1</code>&nbsp;and&nbsp;<code>100</code>.</li>
31+
</ul>
32+
33+
### Related Topics
34+
[[Tree](../../tag/tree/README.md)]
35+
[[Depth-first Search](../../tag/depth-first-search/README.md)]
36+
37+
### Hints
38+
<details>
39+
<summary>Hint 1</summary>
40+
Traverse the tree to find the max depth.
41+
</details>
42+
43+
<details>
44+
<summary>Hint 2</summary>
45+
Traverse the tree again to compute the sum required.
46+
</details>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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](../find-the-team-size "Find the Team Size")
9+
                
10+
[Next >](../all-elements-in-two-binary-search-trees "All Elements in Two Binary Search Trees")
11+
12+
## [1304. Find N Unique Integers Sum up to Zero (Easy)](https://leetcode.com/problems/find-n-unique-integers-sum-up-to-zero "和为零的N个唯一整数")
13+
14+
<p>Given an integer <code>n</code>, return <strong>any</strong> array containing <code>n</code> <strong>unique</strong>&nbsp;integers such that they add up to 0.</p>
15+
16+
<p>&nbsp;</p>
17+
<p><strong>Example 1:</strong></p>
18+
19+
<pre>
20+
<strong>Input:</strong> n = 5
21+
<strong>Output:</strong> [-7,-1,1,3,4]
22+
<strong>Explanation:</strong> These arrays also are accepted [-5,-1,1,2,3] , [-3,-1,2,-2,4].
23+
</pre>
24+
25+
<p><strong>Example 2:</strong></p>
26+
27+
<pre>
28+
<strong>Input:</strong> n = 3
29+
<strong>Output:</strong> [-1,0,1]
30+
</pre>
31+
32+
<p><strong>Example 3:</strong></p>
33+
34+
<pre>
35+
<strong>Input:</strong> n = 1
36+
<strong>Output:</strong> [0]
37+
</pre>
38+
39+
<p>&nbsp;</p>
40+
<p><strong>Constraints:</strong></p>
41+
42+
<ul>
43+
<li><code>1 &lt;= n &lt;= 1000</code></li>
44+
</ul>
45+
46+
### Related Topics
47+
[[Array](../../tag/array/README.md)]
48+
49+
### Hints
50+
<details>
51+
<summary>Hint 1</summary>
52+
Return an array where the values are symmetric. (+x , -x).
53+
</details>
54+
55+
<details>
56+
<summary>Hint 2</summary>
57+
If n is odd, append value 0 in your returned array.
58+
</details>

problems/find-the-team-size/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](../deepest-leaves-sum "Deepest Leaves Sum")
9+
                
10+
[Next >](../find-n-unique-integers-sum-up-to-zero "Find N Unique Integers Sum up to Zero")
11+
12+
## [1303. Find the Team Size (Easy)](https://leetcode.com/problems/find-the-team-size "")
13+
14+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Create table If Not Exists Employee (employee_id int, team_id int);
2+
Truncate table Employee;
3+
insert into Employee (employee_id, team_id) values ('1', '8');
4+
insert into Employee (employee_id, team_id) values ('2', '8');
5+
insert into Employee (employee_id, team_id) values ('3', '8');
6+
insert into Employee (employee_id, team_id) values ('4', '7');
7+
insert into Employee (employee_id, team_id) values ('5', '9');
8+
insert into Employee (employee_id, team_id) values ('6', '9');

problems/jump-game-iii/README.md

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
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](../all-elements-in-two-binary-search-trees "All Elements in Two Binary Search Trees")
9+
                
10+
[Next >](../verbal-arithmetic-puzzle "Verbal Arithmetic Puzzle")
11+
12+
## [1306. Jump Game III (Medium)](https://leetcode.com/problems/jump-game-iii "跳跃游戏 III")
13+
14+
<p>Given an array of non-negative integers <code>arr</code>, you are initially positioned at <code>start</code>&nbsp;index of the array. When you are at index <code>i</code>, you can jump&nbsp;to <code>i + arr[i]</code> or <code>i - arr[i]</code>, check if you can reach to <strong>any</strong> index with value 0.</p>
15+
16+
<p>Notice that you can not jump outside of the array at any time.</p>
17+
18+
<p>&nbsp;</p>
19+
<p><strong>Example 1:</strong></p>
20+
21+
<pre>
22+
<strong>Input:</strong> arr = [4,2,3,0,3,1,2], start = 5
23+
<strong>Output:</strong> true
24+
<strong>Explanation:</strong>
25+
All possible ways to reach at index 3 with value 0 are:
26+
index 5 -&gt; index 4 -&gt; index 1 -&gt; index 3
27+
index 5 -&gt; index 6 -&gt; index 4 -&gt; index 1 -&gt; index 3
28+
</pre>
29+
30+
<p><strong>Example 2:</strong></p>
31+
32+
<pre>
33+
<strong>Input:</strong> arr = [4,2,3,0,3,1,2], start = 0
34+
<strong>Output:</strong> true
35+
<strong>Explanation:
36+
</strong>One possible way to reach at index 3 with value 0 is:
37+
index 0 -&gt; index 4 -&gt; index 1 -&gt; index 3
38+
</pre>
39+
40+
<p><strong>Example 3:</strong></p>
41+
42+
<pre>
43+
<strong>Input:</strong> arr = [3,0,2,1,2], start = 2
44+
<strong>Output:</strong> false
45+
<strong>Explanation: </strong>There is no way to reach at index 1 with value 0.
46+
</pre>
47+
48+
<p>&nbsp;</p>
49+
<p><strong>Constraints:</strong></p>
50+
51+
<ul>
52+
<li><code>1 &lt;= arr.length &lt;= 5 * 10^4</code></li>
53+
<li><code>0 &lt;= arr[i] &lt;&nbsp;arr.length</code></li>
54+
<li><code>0 &lt;= start &lt; arr.length</code></li>
55+
</ul>
56+
57+
### Related Topics
58+
[[Breadth-first Search](../../tag/breadth-first-search/README.md)]
59+
[[Graph](../../tag/graph/README.md)]
60+
61+
### Hints
62+
<details>
63+
<summary>Hint 1</summary>
64+
Think of BFS to solve the problem.
65+
</details>
66+
67+
<details>
68+
<summary>Hint 2</summary>
69+
When you reach a position with a value = 0 then return true.
70+
</details>

problems/maximum-candies-you-can-get-from-boxes/README.md

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

88
[< Previous](../maximum-number-of-occurrences-of-a-substring "Maximum Number of Occurrences of a Substring")
99

10-
Next >
10+
[Next >](../replace-elements-with-greatest-element-on-right-side "Replace Elements with Greatest Element on Right Side")
1111

1212
## [1298. Maximum Candies You Can Get from Boxes (Hard)](https://leetcode.com/problems/maximum-candies-you-can-get-from-boxes "你能从盒子里获得的最大糖果数")
1313

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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](../sum-of-mutated-array-closest-to-target "Sum of Mutated Array Closest to Target")
9+
                
10+
[Next >](../deepest-leaves-sum "Deepest Leaves Sum")
11+
12+
## [1301. Number of Paths with Max Score (Hard)](https://leetcode.com/problems/number-of-paths-with-max-score "最大得分的路径数目")
13+
14+
<p>You are given a square <code>board</code>&nbsp;of characters. You can move on the board starting at the bottom right square marked with the character&nbsp;<code>&#39;S&#39;</code>.</p>
15+
16+
<p>You need&nbsp;to reach the top left square marked with the character <code>&#39;E&#39;</code>. The rest of the squares are labeled either with a numeric character&nbsp;<code>1, 2, ..., 9</code> or with an obstacle <code>&#39;X&#39;</code>. In one move you can go up, left or up-left (diagonally) only if there is no obstacle there.</p>
17+
18+
<p>Return a list of two integers: the first integer is the maximum sum of numeric characters you can collect, and the second is the number of such paths that you can take to get that maximum sum, <strong>taken modulo <code>10^9 + 7</code></strong>.</p>
19+
20+
<p>In case there is no path, return&nbsp;<code>[0, 0]</code>.</p>
21+
22+
<p>&nbsp;</p>
23+
<p><strong>Example 1:</strong></p>
24+
<pre><strong>Input:</strong> board = ["E23","2X2","12S"]
25+
<strong>Output:</strong> [7,1]
26+
</pre><p><strong>Example 2:</strong></p>
27+
<pre><strong>Input:</strong> board = ["E12","1X1","21S"]
28+
<strong>Output:</strong> [4,2]
29+
</pre><p><strong>Example 3:</strong></p>
30+
<pre><strong>Input:</strong> board = ["E11","XXX","11S"]
31+
<strong>Output:</strong> [0,0]
32+
</pre>
33+
<p>&nbsp;</p>
34+
<p><strong>Constraints:</strong></p>
35+
36+
<ul>
37+
<li><code>2 &lt;= board.length == board[i].length &lt;= 100</code></li>
38+
</ul>
39+
40+
### Related Topics
41+
[[Dynamic Programming](../../tag/dynamic-programming/README.md)]
42+
43+
### Hints
44+
<details>
45+
<summary>Hint 1</summary>
46+
Use dynamic programming to find the path with the max score.
47+
</details>
48+
49+
<details>
50+
<summary>Hint 2</summary>
51+
Use another dynamic programming array to count the number of paths with max score.
52+
</details>

0 commit comments

Comments
 (0)