Skip to content

Commit 692a7e4

Browse files
authored
feat: add new lc problems and solutions: No.2773~2777 (doocs#1202)
* No.2773.Height of Special Binary Tree * No.2774.Array Upper Bound * No.2775.Undefined to Null * No.2776.Convert Callback Based Function to Promise Based Function * No.2777.Date Range Generator
1 parent 1c50710 commit 692a7e4

File tree

47 files changed

+1575
-107
lines changed

Some content is hidden

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

47 files changed

+1575
-107
lines changed

solution/0100-0199/0196.Delete Duplicate Emails/README.md

+7-5
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,19 @@ id是该表的主键列。
2121

2222
<p>&nbsp;</p>
2323

24-
<p>编写一个 SQL <strong>删除语句</strong>来 <strong>删除</strong> 所有重复的电子邮件,只保留一个id最小的唯一电子邮件。</p>
24+
<p><strong>删除</strong> 所有重复的电子邮件,只保留一个具有最小 <code>id</code> 的唯一电子邮件。</p>
2525

26-
<p>以 <strong>任意顺序</strong> 返回结果表。 (<strong>注意</strong>: 仅需要写删除语句,将自动对剩余结果进行查询)</p>
26+
<p>(对于 SQL 用户,请注意你应该编写一个 <code>DELETE</code> 语句而不是 <code>SELECT</code> 语句。)</p>
2727

28-
<p>查询结果格式如下所示。</p>
28+
<p>(对于 Pandas 用户,请注意你应该直接修改 <code>Person</code> 表。)</p>
2929

30-
<p>&nbsp;</p>
30+
<p>运行脚本后,显示的答案是 <code>Person</code> 表。驱动程序将首先编译并运行您的代码片段,然后再显示 <code>Person</code> 表。<code>Person</code> 表的最终顺序 <strong>无关紧要</strong> 。</p>
31+
32+
<p>返回结果格式如下示例所示。</p>
3133

3234
<p>&nbsp;</p>
3335

34-
<p><strong>示例 1:</strong></p>
36+
<p><strong class="example">示例 1:</strong></p>
3537

3638
<pre>
3739
<strong>输入:</strong>

solution/0100-0199/0196.Delete Duplicate Emails/README_EN.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@ Each row of this table contains an email. The emails will not contain uppercase
1919

2020
<p>&nbsp;</p>
2121

22-
<p><strong>Delete</strong> all the duplicate emails, keeping only one unique email with the smallest <code>id</code>. (For SQL users, please note that you are supposed to write a <code>DELETE</code> statement and not a <code>SELECT</code> one.)</p>
22+
<p><strong>Delete</strong> all the duplicate emails, keeping only one unique email with the smallest <code>id</code>.</p>
23+
24+
<p>(For SQL users, please note that you are supposed to write a <code>DELETE</code> statement and not a <code>SELECT</code> one.)</p>
25+
26+
<p>(For Pandas users, please note that you are supposed to modify <code>Person</code> in place.)</p>
2327

2428
<p>After running your script, the answer shown is the <code>Person</code> table. The driver will first compile and run your piece of code and then show the <code>Person</code> table. The final order of the <code>Person</code> table <strong>does not matter</strong>.</p>
2529

solution/0400-0499/0460.LFU Cache/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ lfu.get(4); // 返回 4
5959
<p><strong>提示:</strong></p>
6060

6161
<ul>
62-
<li><code>0 &lt;= capacity&nbsp;&lt;= 10<sup>4</sup></code></li>
62+
<li><code>1 &lt;= capacity&nbsp;&lt;= 10<sup>4</sup></code></li>
6363
<li><code>0 &lt;= key &lt;= 10<sup>5</sup></code></li>
6464
<li><code>0 &lt;= value &lt;= 10<sup>9</sup></code></li>
6565
<li>最多调用 <code>2 * 10<sup>5</sup></code> 次 <code>get</code> 和 <code>put</code> 方法</li>

solution/1300-1399/1357.Apply Discount Every n Orders/README_EN.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ cashier.getBill([7,3],[10,10]); // return 4000.0. 5<sup>th<
4040
cashier.getBill([7,5,3,1,6,4,2],[10,10,10,9,9,9,7]); // return 7350.0. 6<sup>th</sup> customer, 50% discount.
4141
// Original bill = 14700, but with
4242
// Actual bill = 14700 * ((100 - 50) / 100) = 7350.
43-
cashier.getBill([2,3,5],[5,3,2]); // return 2500.0. 6<sup>th</sup> customer, no discount.
43+
cashier.getBill([2,3,5],[5,3,2]); // return 2500.0. 7<sup>th</sup> customer, no discount.
4444
</pre>
4545

4646
<p>&nbsp;</p>

solution/1300-1399/1378.Replace Employee ID With The Unique Identifier/README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,15 @@ id 是这张表的主键。
3636

3737
<p>&nbsp;</p>
3838

39-
<p>写一段SQL查询来展示每位用户的<strong> 唯一标识码(unique ID )</strong>;如果某位员工没有唯一标识码,使用 null 填充即可。</p>
39+
<p>展示每位用户的<strong> 唯一标识码(unique ID )</strong>;如果某位员工没有唯一标识码,使用 null 填充即可。</p>
4040

4141
<p>你可以以<strong> 任意</strong> 顺序返回结果表。</p>
4242

43-
<p>查询结果的格式如下例所示。</p>
43+
<p>返回结果的格式如下例所示。</p>
4444

4545
<p>&nbsp;</p>
4646

47-
<p><strong>示例 1:</strong></p>
47+
<p><strong class="example">示例 1:</strong></p>
4848

4949
<pre>
5050
<code><strong>输入:</strong>

solution/1600-1699/1667.Fix Names in a Table/README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@ user_id 是该表的主键。
2121

2222
<p>&nbsp;</p>
2323

24-
<p>编写一个 SQL 查询来修复名字,使得只有第一个字符是大写的,其余都是小写的。</p>
24+
<p>修复名字,使得只有第一个字符是大写的,其余都是小写的。</p>
2525

2626
<p>返回按 <code>user_id</code> 排序的结果表。</p>
2727

28-
<p>查询结果格式示例如下。</p>
28+
<p>返回结果格式示例如下。</p>
2929

3030
<p>&nbsp;</p>
3131

32-
<p><strong>示例 1:</strong></p>
32+
<p><strong class="example">示例 1:</strong></p>
3333

3434
<pre>
3535
<strong>输入:</strong>

solution/1700-1799/1741.Find Total Time Spent by Each Employee/README.md

+14-6
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88

99
<p>表: <code>Employees</code></p>
1010

11-
<pre>+-------------+------+
11+
<pre>
12+
+-------------+------+
1213
| Column Name | Type |
1314
+-------------+------+
1415
| emp_id | int |
@@ -23,14 +24,20 @@ in_time 和 out_time 的取值在1到1440之间。
2324
题目保证同一天没有两个事件在时间上是相交的,并且保证 in_time 小于 out_time。
2425
</pre>
2526

26-
<p> </p>
27+
<p>&nbsp;</p>
2728

28-
<p>编写一个SQL查询以计算每位员工每天在办公室花费的总时间(以分钟为单位)。 请注意,在一天之内,同一员工是可以多次进入和离开办公室的。 在办公室里一次进出所花费的时间为out_time 减去 in_time。</p>
29+
<p>计算每位员工每天在办公室花费的总时间(以分钟为单位)。 请注意,在一天之内,同一员工是可以多次进入和离开办公室的。 在办公室里一次进出所花费的时间为out_time 减去 in_time。</p>
2930

30-
<p>返回结果表单的顺序无要求。<br>
31+
<p>返回结果表单的顺序无要求。<br />
3132
查询结果的格式如下:</p>
3233

33-
<pre>Employees table:
34+
<p>&nbsp;</p>
35+
36+
<p><strong class="example">示例 1:</strong></p>
37+
38+
<pre>
39+
<strong>输入:</strong>
40+
Employees table:
3441
+--------+------------+---------+----------+
3542
| emp_id | event_day | in_time | out_time |
3643
+--------+------------+---------+----------+
@@ -40,7 +47,7 @@ in_time 和 out_time 的取值在1到1440之间。
4047
| 2 | 2020-11-28 | 3 | 33 |
4148
| 2 | 2020-12-09 | 47 | 74 |
4249
+--------+------------+---------+----------+
43-
Result table:
50+
<strong>输出:</strong>
4451
+------------+--------+------------+
4552
| day | emp_id | total_time |
4653
+------------+--------+------------+
@@ -49,6 +56,7 @@ Result table:
4956
| 2020-12-03 | 1 | 41 |
5057
| 2020-12-09 | 2 | 27 |
5158
+------------+--------+------------+
59+
<strong>解释:</strong>
5260
雇员 1 有三次进出: 有两次发生在 2020-11-28 花费的时间为 (32 - 4) + (200 - 55) = 173, 有一次发生在 2020-12-03 花费的时间为 (42 - 1) = 41。
5361
雇员 2 有两次进出: 有一次发生在 2020-11-28 花费的时间为 (33 - 3) = 30, 有一次发生在 2020-12-09 花费的时间为 (74 - 47) = 27。
5462
</pre>

solution/1800-1899/1873.Calculate Special Bonus/README.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,17 @@ employee_id 是这个表的主键。
2222

2323
<p>&nbsp;</p>
2424

25-
<p>写出一个SQL 查询语句,计算每个雇员的奖金。如果一个雇员的id是奇数并且他的名字不是以'M'开头,那么他的奖金是他工资的100%,否则奖金为0。</p>
25+
<p>计算每个雇员的奖金。如果一个雇员的id是奇数并且他的名字不是以'M'开头,那么他的奖金是他工资的100%,否则奖金为0。</p>
2626

27-
<p>Return the result table ordered by <code>employee_id</code>.</p>
27+
<p>&nbsp;</p>
2828

2929
<p>返回的结果集请按照<code>employee_id</code>排序。</p>
3030

31-
<p>查询结果格式如下面的例子所示。</p>
31+
<p>返回结果格式如下面的例子所示。</p>
3232

3333
<p>&nbsp;</p>
3434

35-
<p><strong>示例 1:</strong></p>
35+
<p><strong class="example">示例 1:</strong></p>
3636

3737
<pre>
3838
<strong>输入:</strong>

solution/2500-2599/2582.Pass the Pillow/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ impl Solution {
204204
pub fn pass_the_pillow(n: i32, time: i32) -> i32 {
205205
let mut ans = 1;
206206
let mut k = 1;
207-
207+
208208
for i in 1..=time {
209209
ans += k;
210210

solution/2500-2599/2582.Pass the Pillow/README_EN.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ impl Solution {
191191
pub fn pass_the_pillow(n: i32, time: i32) -> i32 {
192192
let mut ans = 1;
193193
let mut k = 1;
194-
194+
195195
for i in 1..=time {
196196
ans += k;
197197

solution/2500-2599/2586.Count the Number of Vowel Strings in Range/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ function vowelStrings(words: string[], left: number, right: number): number {
155155
```rust
156156
impl Solution {
157157
pub fn vowel_strings(words: Vec<String>, left: i32, right: i32) -> i32 {
158-
let check = |c: u8| -> bool {
158+
let check = |c: u8| -> bool {
159159
c == b'a' || c == b'e' || c == b'i' || c == b'o' || c == b'u'
160160
};
161161

solution/2500-2599/2586.Count the Number of Vowel Strings in Range/README_EN.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ function vowelStrings(words: string[], left: number, right: number): number {
145145
```rust
146146
impl Solution {
147147
pub fn vowel_strings(words: Vec<String>, left: i32, right: i32) -> i32 {
148-
let check = |c: u8| -> bool {
148+
let check = |c: u8| -> bool {
149149
c == b'a' || c == b'e' || c == b'i' || c == b'o' || c == b'u'
150150
};
151151

solution/2700-2799/2715.Execute Cancellable Function With Delay/README.md

+16-5
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,11 @@
1515
<p><strong class="example">示例 1:</strong></p>
1616

1717
<pre>
18-
<b>输入:</b>fn = (x) =&gt; x * 5, args = [2], t = 20, cancelTime = 50
18+
<b>输入:</b>fn = (x) =&gt; x * 5, args = [2], t = 20
1919
<b>输出:</b>[{"time": 20, "returned": 10}]
2020
<b>解释:</b>
21-
const cancel = cancellable(fn, [2], 20); // // 在 t=20ms 时调用 fn(2)
21+
const cancelTime = 50
22+
const cancel = cancellable((x) =&gt; x * 5, [2], 20); // 在 t=20ms 时调用 fn(2)
2223
setTimeout(cancel, 50);
2324

2425
cancelTime(50ms)在延迟时间(20ms)之后,所以 fn(2) 应该在 t=20ms 时调用。fn 的返回值是 10。
@@ -27,17 +28,27 @@ cancelTime(50ms)在延迟时间(20ms)之后,所以 fn(2) 应该在 t=2
2728
<p><strong class="example">示例 2:</strong></p>
2829

2930
<pre>
30-
<b>输入:</b>fn = (x) =&gt; x**2, args = [2], t = 100, cancelTime = 50
31+
<b>输入:</b>fn = (x) =&gt; x**2, args = [2], t = 100
3132
<b>输出:</b>[]
32-
<b>解释:</b>fn(2) 从未被调用,因为 cancelTime(50ms)在延迟时间(100ms)之前。
33+
<b>解释:</b>
34+
const cancelTime = 50
35+
const cancel = cancellable((x) =&gt; x**2, [2], 100); // fn(2) 没被调用
36+
setTimeout(cancel, cancelTime);
37+
38+
fn(2) 从未被调用,因为 cancelTime(50ms)在延迟时间(100ms)之前。
3339
</pre>
3440

3541
<p><strong class="example">示例 3:</strong></p>
3642

3743
<pre>
3844
<b>输入:</b>fn = (x1, x2) =&gt; x1 * x2, args = [2,4], t = 30, cancelTime = 100
3945
<b>输出:</b>[{"time": 30, "returned": 8}]
40-
<b>解释:</b>fn(2) 从未被调用,因为 cancelTime(50ms)在延迟时间(100ms)之前。
46+
<b>解释:</b>
47+
const cancelTime = 100
48+
const cancel = cancellable((x1, x2) =&gt; x1 * x2, [2,4], 30); // fn(2,4) 在 t=30ms 时被调用
49+
setTimeout(cancel, cancelTime);
50+
51+
fn(2) 从未被调用,因为 cancelTime(50ms)在延迟时间(100ms)之前。
4152
</pre>
4253

4354
<p>&nbsp;</p>

solution/2700-2799/2715.Execute Cancellable Function With Delay/README_EN.md

+19-8
Original file line numberDiff line numberDiff line change
@@ -12,29 +12,40 @@
1212
<p><strong class="example">Example 1:</strong></p>
1313

1414
<pre>
15-
<strong>Input:</strong> fn = (x) =&gt; x * 5, args = [2], t = 20, cancelTime = 50
15+
<strong>Input:</strong> fn = (x) =&gt; x * 5, args = [2], t = 20
1616
<strong>Output:</strong> [{&quot;time&quot;: 20, &quot;returned&quot;: 10}]
1717
<strong>Explanation:</strong>
18-
const cancel = cancellable(fn, [2], 20); // fn(2) called at t=20ms
19-
setTimeout(cancel, 50);
18+
const cancelTime = 50
19+
const cancel = cancellable((x) =&gt; x * 5, [2], 20); // fn(2) called at t=20ms
20+
setTimeout(cancel, cancelTime);
2021

21-
the cancelTime (50ms) is after the delay time (20ms), so fn(2) should be called at t=20ms. The value returned from fn is 10.
22+
The cancellation was scheduled to occur after a delay of cancelTime (50ms), which happened after the execution of fn(2) at 20ms.
2223
</pre>
2324

2425
<p><strong class="example">Example 2:</strong></p>
2526

2627
<pre>
27-
<strong>Input:</strong> fn = (x) =&gt; x**2, args = [2], t = 100, cancelTime = 50
28+
<strong>Input:</strong> fn = (x) =&gt; x**2, args = [2], t = 100
2829
<strong>Output:</strong> []
29-
<strong>Explanation:</strong> fn(2) was never called because cancelTime (50ms) is before the delay time (100ms).
30+
<strong>Explanation:</strong>
31+
const cancelTime = 50
32+
const cancel = cancellable((x) =&gt; x**2, [2], 100); // fn(2) not called
33+
setTimeout(cancel, cancelTime);
34+
35+
The cancellation was scheduled to occur after a delay of cancelTime (50ms), which happened before the execution of fn(2) at 100ms, resulting in fn(2) never being called.
3036
</pre>
3137

3238
<p><strong class="example">Example 3:</strong></p>
3339

3440
<pre>
35-
<strong>Input:</strong> fn = (x1, x2) =&gt; x1 * x2, args = [2,4], t = 30, cancelTime = 100
41+
<strong>Input:</strong> fn = (x1, x2) =&gt; x1 * x2, args = [2,4], t = 30
3642
<strong>Output:</strong> [{&quot;time&quot;: 30, &quot;returned&quot;: 8}]
37-
<strong>Explanation:</strong> fn(2, 4) was called at t=30ms because cancelTime &gt; t.
43+
<strong>Explanation:</strong>
44+
const cancelTime = 100
45+
const cancel = cancellable((x1, x2) =&gt; x1 * x2, [2,4], 30); // fn(2,4) called at t=30ms
46+
setTimeout(cancel, cancelTime);
47+
48+
The cancellation was scheduled to occur after a delay of cancelTime (100ms), which happened after the execution of fn(2,4) at 30ms.
3849
</pre>
3950

4051
<p>&nbsp;</p>

solution/2700-2799/2721.Execute Asynchronous Functions in Parallel/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ promiseAll(functions).then(console.log); // [5]
6565
<p><strong>提示:</strong></p>
6666

6767
<ul>
68-
<li><code>functions&nbsp;is an array of functions that returns promises</code></li>
68+
<li><code>函数 functions 是一个返回 Promise 的函数数组</code></li>
6969
<li><code>1 &lt;= functions.length &lt;= 10</code></li>
7070
</ul>
7171

solution/2700-2799/2721.Execute Asynchronous Functions in Parallel/README_EN.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<p><code>promise</code> resolves:</p>
1010

1111
<ul>
12-
<li>When all the promises returned from&nbsp;<code>functions</code>&nbsp;were resolved successfully.&nbsp;The resolved&nbsp;value of&nbsp;<code>promise</code> should be an array of all the resolved values of promises in the same order as they were in the&nbsp;<code>functions.</code></li>
12+
<li>When all the promises returned from&nbsp;<code>functions</code>&nbsp;were resolved successfully.&nbsp;The resolved&nbsp;value of&nbsp;<code>promise</code> should be an array of all the resolved values of promises in the same order as they were in the&nbsp;<code>functions</code>.</li>
1313
</ul>
1414

1515
<p><code>promise</code> rejects:</p>

solution/2700-2799/2725.Interval Cancellation/README.md

+19-5
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,19 @@
2323
{"time": 80, "returned": 8},
2424
{"time": 100, "returned": 8}
2525
]
26-
<strong>解释:</strong> 每隔 20ms,调用 fn(4)。直到 t=110ms,然后取消。
26+
<strong>解释:</strong>
27+
const cancelT = 110
2728
const cancel = cancellable(x =&gt; x * 2, [4], 20);
28-
setTimeout(cancel, 110);
29+
setTimeout(cancel, cancelT);
30+
每隔 20ms,调用 fn(4)。
2931
第一次调用 fn 是在 0ms。fn(4) 返回 8。
3032
第二次调用 fn 是在 20ms。fn(4) 返回 8。
3133
第三次调用 fn 是在 40ms。fn(4) 返回 8。
3234
第四次调用 fn 是在&nbsp;60ms。fn(4) 返回 8。
3335
第五次调用 fn 是在 80ms。fn(4) 返回 8。
34-
第六次调用 fn 是在 100ms。fn(4) 返回 8。</pre>
36+
第六次调用 fn 是在 100ms。fn(4) 返回 8。
37+
在 t=110ms 时取消。
38+
</pre>
3539

3640
<p><strong class="example">示例 2:</strong></p>
3741

@@ -46,7 +50,12 @@ setTimeout(cancel, 110);
4650
{"time": 100, "returned": 10},
4751
{"time": 125, "returned": 10}
4852
]
49-
<strong>解释:</strong>每隔 25ms,调用 fn(2, 5)。直到 t=140ms,然后取消。
53+
<strong>解释:
54+
</strong>const cancelT = 140
55+
const cancel = cancellable((x1, x2) =&gt; (x1 * x2), [2, 5], 25);
56+
setTimeout(cancel, cancelT);
57+
58+
每隔 25ms,调用 fn(2, 5)。直到 t=140ms,然后取消。
5059
第一次调用 fn 是在 0ms
5160
第二次调用 fn 是在 25ms
5261
第三次调用 fn 是在 50ms
@@ -67,7 +76,12 @@ setTimeout(cancel, 110);
6776
{"time": 100, "returned": 9},
6877
{"time": 150, "returned": 9}
6978
]
70-
<b>解释:</b>每隔 50ms,调用 fn(5, 1, 3)。直到 t=180ms,然后取消。
79+
<b>解释:</b>
80+
const cancelT = 180
81+
const cancel = cancellable((x1, x2, x3) =&gt; (x1 + x2 + x3), [5, 1, 3], 50);
82+
setTimeout(cancel, cancelT);
83+
84+
每隔 50ms,调用 fn(5, 1, 3)。直到 t=180ms,然后取消。
7185
第一次调用 fn 是在 0ms
7286
第二次调用 fn 是在 50ms
7387
第三次调用 fn 是在 100ms

0 commit comments

Comments
 (0)