Skip to content

Commit f217b06

Browse files
author
Shuo
committed
A: new
1 parent 9904ed4 commit f217b06

File tree

115 files changed

+1828
-1210
lines changed

Some content is hidden

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

115 files changed

+1828
-1210
lines changed

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,22 @@ LeetCode Problems' Solutions
7070

7171
| # | Title | Solution | Difficulty |
7272
| :-: | - | - | :-: |
73+
| <span id="1707">1707</span> | [Maximum XOR With an Element From Array](https://leetcode.com/problems/maximum-xor-with-an-element-from-array "与数组中元素的最大异或值") | [Go](problems/maximum-xor-with-an-element-from-array) | Hard |
74+
| <span id="1706">1706</span> | [Where Will the Ball Fall](https://leetcode.com/problems/where-will-the-ball-fall "球会落何处") | [Go](problems/where-will-the-ball-fall) | Medium |
75+
| <span id="1705">1705</span> | [Maximum Number of Eaten Apples](https://leetcode.com/problems/maximum-number-of-eaten-apples "吃苹果的最大数目") | [Go](problems/maximum-number-of-eaten-apples) | Medium |
76+
| <span id="1704">1704</span> | [Determine if String Halves Are Alike](https://leetcode.com/problems/determine-if-string-halves-are-alike "判断字符串的两半是否相似") | [Go](problems/determine-if-string-halves-are-alike) | Easy |
77+
| <span id="1703">1703</span> | [Minimum Adjacent Swaps for K Consecutive Ones](https://leetcode.com/problems/minimum-adjacent-swaps-for-k-consecutive-ones "得到连续 K 个 1 的最少相邻交换次数") | [Go](problems/minimum-adjacent-swaps-for-k-consecutive-ones) | Hard |
78+
| <span id="1702">1702</span> | [Maximum Binary String After Change](https://leetcode.com/problems/maximum-binary-string-after-change "修改后的最大二进制字符串") | [Go](problems/maximum-binary-string-after-change) | Medium |
79+
| <span id="1701">1701</span> | [Average Waiting Time](https://leetcode.com/problems/average-waiting-time "平均等待时间") | [Go](problems/average-waiting-time) | Medium |
80+
| <span id="1700">1700</span> | [Number of Students Unable to Eat Lunch](https://leetcode.com/problems/number-of-students-unable-to-eat-lunch "无法吃午餐的学生数量") | [Go](problems/number-of-students-unable-to-eat-lunch) | Easy |
81+
| <span id="1699">1699</span> | [Number of Calls Between Two Persons](https://leetcode.com/problems/number-of-calls-between-two-persons) 🔒 | [MySQL](problems/number-of-calls-between-two-persons) | Medium |
82+
| <span id="1698">1698</span> | [Number of Distinct Substrings in a String](https://leetcode.com/problems/number-of-distinct-substrings-in-a-string) 🔒 | [Go](problems/number-of-distinct-substrings-in-a-string) | Medium |
83+
| <span id="1697">1697</span> | [Checking Existence of Edge Length Limited Paths](https://leetcode.com/problems/checking-existence-of-edge-length-limited-paths "检查边长度限制的路径是否存在") | [Go](problems/checking-existence-of-edge-length-limited-paths) | Hard |
84+
| <span id="1696">1696</span> | [Jump Game VI](https://leetcode.com/problems/jump-game-vi "跳跃游戏 VI") | [Go](problems/jump-game-vi) | Medium |
85+
| <span id="1695">1695</span> | [Maximum Erasure Value](https://leetcode.com/problems/maximum-erasure-value "删除子数组的最大得分") | [Go](problems/maximum-erasure-value) | Medium |
86+
| <span id="1694">1694</span> | [Reformat Phone Number](https://leetcode.com/problems/reformat-phone-number "重新格式化电话号码") | [Go](problems/reformat-phone-number) | Easy |
87+
| <span id="1693">1693</span> | [Daily Leads and Partners](https://leetcode.com/problems/daily-leads-and-partners) 🔒 | [MySQL](problems/daily-leads-and-partners) | Easy |
88+
| <span id="1692">1692</span> | [Count Ways to Distribute Candies](https://leetcode.com/problems/count-ways-to-distribute-candies) 🔒 | [Go](problems/count-ways-to-distribute-candies) | Hard |
7389
| <span id="1691">1691</span> | [Maximum Height by Stacking Cuboids](https://leetcode.com/problems/maximum-height-by-stacking-cuboids "堆叠长方体的最大高度") | [Go](problems/maximum-height-by-stacking-cuboids) | Hard |
7490
| <span id="1690">1690</span> | [Stone Game VII](https://leetcode.com/problems/stone-game-vii "石子游戏 VII") | [Go](problems/stone-game-vii) | Medium |
7591
| <span id="1689">1689</span> | [Partitioning Into Minimum Number Of Deci-Binary Numbers](https://leetcode.com/problems/partitioning-into-minimum-number-of-deci-binary-numbers "十-二进制数的最少数目") | [Go](problems/partitioning-into-minimum-number-of-deci-binary-numbers) | Medium |
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
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](../number-of-students-unable-to-eat-lunch "Number of Students Unable to Eat Lunch")
9+
                
10+
[Next >](../maximum-binary-string-after-change "Maximum Binary String After Change")
11+
12+
## [1701. Average Waiting Time (Medium)](https://leetcode.com/problems/average-waiting-time "平均等待时间")
13+
14+
<p>There is a restaurant with a single chef. You are given an array <code>customers</code>, where <code>customers[i] = [arrival<sub>i</sub>, time<sub>i</sub>]:</code></p>
15+
16+
<ul>
17+
<li><code>arrival<sub>i</sub></code> is the arrival time of the <code>i<sup>th</sup></code> customer. The arrival times are sorted in <strong>non-decreasing</strong> order.</li>
18+
<li><code>time<sub>i</sub></code> is the time needed to prepare the order of the <code>i<sup>th</sup></code> customer.</li>
19+
</ul>
20+
21+
<p>When a customer arrives, he gives the chef his order, and the chef starts preparing it once he is idle. The customer waits till the chef finishes preparing his order. The chef does not prepare food for more than one customer at a time. The chef prepares food for customers <strong>in the order they were given in the input</strong>.</p>
22+
23+
<p>Return <em>the <strong>average</strong> waiting time of all customers</em>. Solutions within <code>10<sup>-5</sup></code> from the actual answer are considered accepted.</p>
24+
25+
<p>&nbsp;</p>
26+
<p><strong>Example 1:</strong></p>
27+
28+
<pre>
29+
<strong>Input:</strong> customers = [[1,2],[2,5],[4,3]]
30+
<strong>Output:</strong> 5.00000
31+
<strong>Explanation:
32+
</strong>1) The first customer arrives at time 1, the chef takes his order and starts preparing it immediately at time 1, and finishes at time 3, so the waiting time of the first customer is 3 - 1 = 2.
33+
2) The second customer arrives at time 2, the chef takes his order and starts preparing it at time 3, and finishes at time 8, so the waiting time of the second customer is 8 - 2 = 6.
34+
3) The third customer arrives at time 4, the chef takes his order and starts preparing it at time 8, and finishes at time 11, so the waiting time of the third customer is 11 - 4 = 7.
35+
So the average waiting time = (2 + 6 + 7) / 3 = 5.
36+
</pre>
37+
38+
<p><strong>Example 2:</strong></p>
39+
40+
<pre>
41+
<strong>Input:</strong> customers = [[5,2],[5,4],[10,3],[20,1]]
42+
<strong>Output:</strong> 3.25000
43+
<strong>Explanation:
44+
</strong>1) The first customer arrives at time 5, the chef takes his order and starts preparing it immediately at time 5, and finishes at time 7, so the waiting time of the first customer is 7 - 5 = 2.
45+
2) The second customer arrives at time 5, the chef takes his order and starts preparing it at time 7, and finishes at time 11, so the waiting time of the second customer is 11 - 5 = 6.
46+
3) The third customer arrives at time 10, the chef takes his order and starts preparing it at time 11, and finishes at time 14, so the waiting time of the third customer is 14 - 10 = 4.
47+
4) The fourth customer arrives at time 20, the chef takes his order and starts preparing it immediately at time 20, and finishes at time 21, so the waiting time of the fourth customer is 21 - 20 = 1.
48+
So the average waiting time = (2 + 6 + 4 + 1) / 4 = 3.25.
49+
</pre>
50+
51+
<p>&nbsp;</p>
52+
<p><strong>Constraints:</strong></p>
53+
54+
<ul>
55+
<li><code>1 &lt;= customers.length &lt;= 10<sup>5</sup></code></li>
56+
<li><code>1 &lt;= arrival<sub>i</sub>, time<sub>i</sub> &lt;= 10<sup>4</sup></code></li>
57+
<li><code>arrival<sub>i&nbsp;</sub>&lt;= arrival<sub>i+1</sub></code></li>
58+
</ul>
59+
60+
### Related Topics
61+
[[Array](../../tag/array/README.md)]
62+
63+
### Hints
64+
<details>
65+
<summary>Hint 1</summary>
66+
Iterate on the customers, maintaining the time the chef will finish the previous orders.
67+
</details>
68+
69+
<details>
70+
<summary>Hint 2</summary>
71+
If that time is before the current arrival time, the chef starts immediately. Else, the current customer waits till the chef finishes, and then the chef starts.
72+
</details>
73+
74+
<details>
75+
<summary>Hint 3</summary>
76+
Update the running time by the time when the chef starts preparing + preparation time.
77+
</details>

problems/balanced-binary-tree/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
### Related Topics
5353
[[Tree](../../tag/tree/README.md)]
5454
[[Depth-first Search](../../tag/depth-first-search/README.md)]
55+
[[Recursion](../../tag/recursion/README.md)]
5556

5657
### Similar Questions
5758
1. [Maximum Depth of Binary Tree](../maximum-depth-of-binary-tree) (Easy)

problems/basic-calculator/README.md

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,33 +11,37 @@
1111

1212
## [224. Basic Calculator (Hard)](https://leetcode.com/problems/basic-calculator "基本计算器")
1313

14-
<p>Implement a basic calculator to evaluate a simple expression string.</p>
15-
16-
<p>The expression string may contain open <code>(</code> and closing parentheses <code>)</code>, the plus <code>+</code> or minus sign <code>-</code>, <b>non-negative</b> integers and empty spaces <code> </code>.</p>
14+
<p>Given a string <code>s</code> representing an expression, implement a basic calculator to evaluate it.</p>
1715

16+
<p>&nbsp;</p>
1817
<p><strong>Example 1:</strong></p>
1918

2019
<pre>
21-
<strong>Input:</strong> &quot;1 + 1&quot;
20+
<strong>Input:</strong> s = &quot;1 + 1&quot;
2221
<strong>Output:</strong> 2
2322
</pre>
2423

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

2726
<pre>
28-
<strong>Input:</strong> &quot; 2-1 + 2 &quot;
29-
<strong>Output:</strong> 3</pre>
27+
<strong>Input:</strong> s = &quot; 2-1 + 2 &quot;
28+
<strong>Output:</strong> 3
29+
</pre>
3030

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

3333
<pre>
34-
<strong>Input:</strong> &quot;(1+(4+5+2)-3)+(6+8)&quot;
35-
<strong>Output:</strong> 23</pre>
36-
<b>Note:</b>
34+
<strong>Input:</strong> s = &quot;(1+(4+5+2)-3)+(6+8)&quot;
35+
<strong>Output:</strong> 23
36+
</pre>
37+
38+
<p>&nbsp;</p>
39+
<p><strong>Constraints:</strong></p>
3740

3841
<ul>
39-
<li>You may assume that the given expression is always valid.</li>
40-
<li><b>Do not</b> use the <code>eval</code> built-in library function.</li>
42+
<li><code>1 &lt;= s.length &lt;= 3&nbsp;* 10<sup>5</sup></code></li>
43+
<li><code>s</code> consists of digits, <code>&#39;+&#39;</code>, <code>&#39;-&#39;</code>, <code>&#39;(&#39;</code>, <code>&#39;)&#39;</code>, and <code>&#39; &#39;</code>.</li>
44+
<li><code>s</code> represents a valid expression.</li>
4145
</ul>
4246

4347
### Related Topics

problems/binary-tree-level-order-traversal-ii/README.md

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

1010
[Next >](../convert-sorted-array-to-binary-search-tree "Convert Sorted Array to Binary Search Tree")
1111

12-
## [107. Binary Tree Level Order Traversal II (Easy)](https://leetcode.com/problems/binary-tree-level-order-traversal-ii "二叉树的层次遍历 II")
12+
## [107. Binary Tree Level Order Traversal II (Easy)](https://leetcode.com/problems/binary-tree-level-order-traversal-ii "二叉树的层序遍历 II")
1313

1414
<p>Given a binary tree, return the <i>bottom-up level order</i> traversal of its nodes' values. (ie, from left to right, level by level from leaf to root).</p>
1515

problems/binary-tree-maximum-path-sum/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
### Related Topics
4242
[[Tree](../../tag/tree/README.md)]
4343
[[Depth-first Search](../../tag/depth-first-search/README.md)]
44+
[[Recursion](../../tag/recursion/README.md)]
4445

4546
### Similar Questions
4647
1. [Path Sum](../path-sum) (Easy)

problems/binary-tree-zigzag-level-order-traversal/README.md

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

1010
[Next >](../maximum-depth-of-binary-tree "Maximum Depth of Binary Tree")
1111

12-
## [103. Binary Tree Zigzag Level Order Traversal (Medium)](https://leetcode.com/problems/binary-tree-zigzag-level-order-traversal "二叉树的锯齿形层次遍历")
12+
## [103. Binary Tree Zigzag Level Order Traversal (Medium)](https://leetcode.com/problems/binary-tree-zigzag-level-order-traversal "二叉树的锯齿形层序遍历")
1313

1414
<p>Given a binary tree, return the <i>zigzag level order</i> traversal of its nodes' values. (ie, from left to right, then right to left for the next level and alternate between).</p>
1515

problems/burst-balloons/README.md

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,26 +11,38 @@
1111

1212
## [312. Burst Balloons (Hard)](https://leetcode.com/problems/burst-balloons "戳气球")
1313

14-
<p>Given <code>n</code> balloons, indexed from <code>0</code> to <code>n-1</code>. Each balloon is painted with a number on it represented by array <code>nums</code>. You are asked to burst all the balloons. If the you burst balloon <code>i</code> you will get <code>nums[left] * nums[i] * nums[right]</code> coins. Here <code>left</code> and <code>right</code> are adjacent indices of <code>i</code>. After the burst, the <code>left</code> and <code>right</code> then becomes adjacent.</p>
14+
<p>You are given <code>n</code> balloons, indexed from <code>0</code> to <code>n - 1</code>. Each balloon is painted with a number on it represented by an array <code>nums</code>. You are asked to burst all the balloons.</p>
1515

16-
<p>Find the maximum coins you can collect by bursting the balloons wisely.</p>
16+
<p>If you burst the <code>i<sup>th</sup></code> balloon, you will get <code>nums[left] * nums[i] * nums[right]</code> coins. Here <code>left</code> and <code>right</code> are adjacent indices of <code>i</code>. After the burst, the <code>left</code> and <code>right</code> then becomes adjacent.</p>
1717

18-
<p><b>Note:</b></p>
18+
<p>Return <em>the maximum coins you can collect by bursting the balloons wisely</em>.</p>
1919

20-
<ul>
21-
<li>You may imagine <code>nums[-1] = nums[n] = 1</code>. They are not real therefore you can not burst them.</li>
22-
<li>0 &le; <code>n</code> &le; 500, 0 &le; <code>nums[i]</code> &le; 100</li>
23-
</ul>
20+
<p>&nbsp;</p>
21+
<p><strong>Example 1:</strong></p>
22+
23+
<pre>
24+
<strong>Input:</strong> nums = [3,1,5,8]
25+
<strong>Output:</strong> 167
26+
<code><strong>Explanation:
27+
</strong></code>nums = [3,1,5,8] --&gt; [3,5,8] --&gt; [3,8] --&gt; [8] --&gt; []
28+
coins = 3*1*5 + 3*5*8 + 1*3*8 + 1*8*1 = 167</pre>
2429

25-
<p><b>Example:</b></p>
30+
<p><strong>Example 2:</strong></p>
2631

2732
<pre>
28-
<b>Input:</b> <code>[3,1,5,8]</code>
29-
<b>Output:</b> <code>167
30-
<strong>Explanation: </strong></code>nums = [3,1,5,8] --&gt; [3,5,8] --&gt; [3,8] --&gt; [8] --&gt; []
31-
&nbsp; coins = 3*1*5 + 3*5*8 + 1*3*8 + 1*8*1 = 167
33+
<strong>Input:</strong> nums = [1,5]
34+
<strong>Output:</strong> 10
3235
</pre>
3336

37+
<p>&nbsp;</p>
38+
<p><strong>Constraints:</strong></p>
39+
40+
<ul>
41+
<li><code>n == nums.length</code></li>
42+
<li><code>1 &lt;= n &lt;= 500</code></li>
43+
<li><code>0 &lt;= nums[i] &lt;= 100</code></li>
44+
</ul>
45+
3446
### Related Topics
3547
[[Divide and Conquer](../../tag/divide-and-conquer/README.md)]
3648
[[Dynamic Programming](../../tag/dynamic-programming/README.md)]

problems/check-if-array-pairs-are-divisible-by-k/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,10 @@
6161

6262
<ul>
6363
<li><code>arr.length == n</code></li>
64-
<li><code>1 &lt;= n &lt;= 10^5</code></li>
64+
<li><code>1 &lt;= n &lt;= 10<sup>5</sup></code></li>
6565
<li><code>n</code> is even.</li>
66-
<li><code>-10^9 &lt;= arr[i] &lt;= 10^9</code></li>
67-
<li><code>1 &lt;= k &lt;= 10^5</code></li>
66+
<li><code>-10<sup>9</sup> &lt;= arr[i] &lt;= 10<sup>9</sup></code></li>
67+
<li><code>1 &lt;= k &lt;= 10<sup>5</sup></code></li>
6868
</ul>
6969

7070
### Related Topics
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
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](../jump-game-vi "Jump Game VI")
9+
                
10+
[Next >](../number-of-distinct-substrings-in-a-string "Number of Distinct Substrings in a String")
11+
12+
## [1697. Checking Existence of Edge Length Limited Paths (Hard)](https://leetcode.com/problems/checking-existence-of-edge-length-limited-paths "检查边长度限制的路径是否存在")
13+
14+
<p>An undirected graph of <code>n</code> nodes is defined by <code>edgeList</code>, where <code>edgeList[i] = [u<sub>i</sub>, v<sub>i</sub>, dis<sub>i</sub>]</code> denotes an edge between nodes <code>u<sub>i</sub></code> and <code>v<sub>i</sub></code> with distance <code>dis<sub>i</sub></code>. Note that there may be <strong>multiple</strong> edges between two nodes.</p>
15+
16+
<p>Given an array <code>queries</code>, where <code>queries[j] = [p<sub>j</sub>, q<sub>j</sub>, limit<sub>j</sub>]</code>, your task is to determine for each <code>queries[j]</code> whether there is a path between <code>p<sub>j</sub></code> and <code>q<sub>j</sub></code><sub> </sub>such that each edge on the path has a distance <strong>strictly less than</strong> <code>limit<sub>j</sub></code> .</p>
17+
18+
<p>Return <em>a <strong>boolean array</strong> </em><code>answer</code><em>, where </em><code>answer.length == queries.length</code> <em>and the </em><code>j<sup>th</sup></code> <em>value of </em><code>answer</code> <em>is </em><code>true</code><em> if there is a path for </em><code>queries[j]</code><em> is </em><code>true</code><em>, and </em><code>false</code><em> otherwise</em>.</p>
19+
20+
<p>&nbsp;</p>
21+
<p><strong>Example 1:</strong></p>
22+
<img alt="" src="https://assets.leetcode.com/uploads/2020/12/08/h.png" style="width: 267px; height: 262px;" />
23+
<pre>
24+
<strong>Input:</strong> n = 3, edgeList = [[0,1,2],[1,2,4],[2,0,8],[1,0,16]], queries = [[0,1,2],[0,2,5]]
25+
<strong>Output:</strong> [false,true]
26+
<strong>Explanation:</strong> The above figure shows the given graph. Note that there are two overlapping edges between 0 and 1 with distances 2 and 16.
27+
For the first query, between 0 and 1 there is no path where each distance is less than 2, thus we return false for this query.
28+
For the second query, there is a path (0 -&gt; 1 -&gt; 2) of two edges with distances less than 5, thus we return true for this query.
29+
</pre>
30+
31+
<p><strong>Example 2:</strong></p>
32+
<img alt="" src="https://assets.leetcode.com/uploads/2020/12/08/q.png" style="width: 390px; height: 358px;" />
33+
<pre>
34+
<strong>Input:</strong> n = 5, edgeList = [[0,1,10],[1,2,5],[2,3,9],[3,4,13]], queries = [[0,4,14],[1,4,13]]
35+
<strong>Output:</strong> [true,false]
36+
<strong>Exaplanation:</strong> The above figure shows the given graph.
37+
</pre>
38+
39+
<p>&nbsp;</p>
40+
<p><strong>Constraints:</strong></p>
41+
42+
<ul>
43+
<li><code>2 &lt;= n &lt;= 10<sup>5</sup></code></li>
44+
<li><code>1 &lt;= edgeList.length, queries.length &lt;= 10<sup>5</sup></code></li>
45+
<li><code>edgeList[i].length == 3</code></li>
46+
<li><code>queries[j].length == 3</code></li>
47+
<li><code>0 &lt;= u<sub>i</sub>, v<sub>i</sub>, p<sub>j</sub>, q<sub>j</sub> &lt;= n - 1</code></li>
48+
<li><code>u<sub>i</sub> != v<sub>i</sub></code></li>
49+
<li><code>p<sub>j</sub> != q<sub>j</sub></code></li>
50+
<li><code>1 &lt;= dis<sub>i</sub>, limit<sub>j</sub> &lt;= 10<sup>9</sup></code></li>
51+
<li>There may be <strong>multiple</strong> edges between two nodes.</li>
52+
</ul>
53+
54+
### Related Topics
55+
[[Sort](../../tag/sort/README.md)]
56+
[[Union Find](../../tag/union-find/README.md)]
57+
58+
### Hints
59+
<details>
60+
<summary>Hint 1</summary>
61+
All the queries are given in advance. Is there a way you can reorder the queries to avoid repeated computations?
62+
</details>

0 commit comments

Comments
 (0)