Skip to content

Commit 243de48

Browse files
authored
chore: update lc problems (doocs#1415)
1 parent b54b83f commit 243de48

File tree

95 files changed

+496
-416
lines changed

Some content is hidden

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

95 files changed

+496
-416
lines changed

solution/0000-0099/0001.Two Sum/README_EN.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
</ul>
4545

4646
<p>&nbsp;</p>
47-
<strong>Follow-up:&nbsp;</strong>Can you come up with an algorithm that is less than&nbsp;<code>O(n<sup>2</sup>)&nbsp;</code>time complexity?
47+
<strong>Follow-up:&nbsp;</strong>Can you come up with an algorithm that is less than <code>O(n<sup>2</sup>)</code><font face="monospace">&nbsp;</font>time complexity?
4848

4949
## Solutions
5050

solution/0000-0099/0095.Unique Binary Search Trees II/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ public:
211211
// pub left: Option<Rc<RefCell<TreeNode>>>,
212212
// pub right: Option<Rc<RefCell<TreeNode>>>,
213213
// }
214-
//
214+
//
215215
// impl TreeNode {
216216
// #[inline]
217217
// pub fn new(val: i32) -> Self {

solution/0000-0099/0095.Unique Binary Search Trees II/README_EN.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ public:
197197
// pub left: Option<Rc<RefCell<TreeNode>>>,
198198
// pub right: Option<Rc<RefCell<TreeNode>>>,
199199
// }
200-
//
200+
//
201201
// impl TreeNode {
202202
// #[inline]
203203
// pub fn new(val: i32) -> Self {

solution/0100-0199/0176.Second Highest Salary/README_EN.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@
1313
| id | int |
1414
| salary | int |
1515
+-------------+------+
16-
In SQL, id is the primary key column for this table.
16+
id is the primary key (column with unique values) for this table.
1717
Each row of this table contains information about the salary of an employee.
1818
</pre>
1919

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

22-
<p>Find&nbsp;the second highest salary from the <code>Employee</code> table. If there is no second highest salary,&nbsp;return&nbsp;<code>null (return&nbsp;None in Pandas)</code>.</p>
22+
<p>Write a solution to find&nbsp;the second highest salary from the <code>Employee</code> table. If there is no second highest salary,&nbsp;return&nbsp;<code>null (return&nbsp;None in Pandas)</code>.</p>
2323

2424
<p>The result format is in the following example.</p>
2525

solution/0100-0199/0177.Nth Highest Salary/README_EN.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@
1313
| id | int |
1414
| salary | int |
1515
+-------------+------+
16-
In SQL, id is the primary key column for this table.
16+
id is the primary key (column with unique values) for this table.
1717
Each row of this table contains information about the salary of an employee.
1818
</pre>
1919

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

22-
<p>Find the <code>n<sup>th</sup></code> highest salary from the <code>Employee</code> table. If there is no <code>n<sup>th</sup></code> highest salary, return&nbsp;<code>null</code>.</p>
22+
<p>Write a solution to find the <code>n<sup>th</sup></code> highest salary from the <code>Employee</code> table. If there is no <code>n<sup>th</sup></code> highest salary, return&nbsp;<code>null</code>.</p>
2323

2424
<p>The result format is in the following example.</p>
2525

solution/0100-0199/0178.Rank Scores/README_EN.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@
1313
| id | int |
1414
| score | decimal |
1515
+-------------+---------+
16-
In SQL, id is the primary key for this table.
16+
id is the primary key (column with unique values) for this table.
1717
Each row of this table contains the score of a game. Score is a floating point value with two decimal places.
1818
</pre>
1919

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

22-
<p>Find the rank of the scores. The ranking should be calculated according to the following rules:</p>
22+
<p>Write a solution to find the rank of the scores. The ranking should be calculated according to the following rules:</p>
2323

2424
<ul>
2525
<li>The scores should be ranked from the highest to the lowest.</li>

solution/0100-0199/0180.Consecutive Numbers/README.md

+5-4
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,16 @@
1515
| id | int |
1616
| num | varchar |
1717
+-------------+---------+
18-
id 是这个表的主键。</pre>
18+
在 SQL 中,id 是该表的主键。
19+
id 是一个自增列。</pre>
1920

2021
<p>&nbsp;</p>
2122

22-
<p>编写一个 SQL 查询,查找所有至少连续出现三次的数字。</p>
23+
<p>找出所有至少连续出现三次的数字。</p>
2324

2425
<p>返回的结果表中的数据可以按 <strong>任意顺序</strong> 排列。</p>
2526

26-
<p>查询结果格式如下面的例子所示:</p>
27+
<p>结果格式如下面的例子所示:</p>
2728

2829
<p>&nbsp;</p>
2930

@@ -33,7 +34,7 @@ id 是这个表的主键。</pre>
3334
<strong>输入:</strong>
3435
Logs 表:
3536
+----+-----+
36-
| Id | Num |
37+
| id | num |
3738
+----+-----+
3839
| 1 | 1 |
3940
| 2 | 1 |

solution/0100-0199/0183.Customers Who Never Order/README_EN.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
| id | int |
1414
| name | varchar |
1515
+-------------+---------+
16-
In SQL, id is the primary key column for this table.
16+
id is the primary key (column with unique values) for this table.
1717
Each row of this table indicates the ID and name of a customer.
1818
</pre>
1919

@@ -28,14 +28,14 @@ Each row of this table indicates the ID and name of a customer.
2828
| id | int |
2929
| customerId | int |
3030
+-------------+------+
31-
In SQL, id is the primary key column for this table.
32-
customerId is a foreign key (join key in Pandas) of the ID from the Customers table.
31+
id is the primary key (column with unique values) for this table.
32+
customerId is a foreign key (reference columns) of the ID from the Customers table.
3333
Each row of this table indicates the ID of an order and the ID of the customer who ordered it.
3434
</pre>
3535

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

38-
<p>Find all customers who never order anything.</p>
38+
<p>Write a solution to find all customers who never order anything.</p>
3939

4040
<p>Return the result table in <strong>any order</strong>.</p>
4141

solution/0100-0199/0184.Department Highest Salary/README_EN.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
| salary | int |
1616
| departmentId | int |
1717
+--------------+---------+
18-
In SQL, id is the primary key column for this table.
19-
departmentId is a foreign key (join key in Pandas) of the ID from the <code>Department </code>table.
18+
id is the primary key (column with unique values) for this table.
19+
departmentId is a foreign key (reference columns) of the ID from the <code>Department </code>table.
2020
Each row of this table indicates the ID, name, and salary of an employee. It also contains the ID of their department.
2121
</pre>
2222

@@ -31,13 +31,13 @@ Each row of this table indicates the ID, name, and salary of an employee. It als
3131
| id | int |
3232
| name | varchar |
3333
+-------------+---------+
34-
In SQL, id is the primary key column for this table. It is guaranteed that department name is not <code>NULL.</code>
34+
id is the primary key (column with unique values) for this table. It is guaranteed that department name is not <code>NULL.</code>
3535
Each row of this table indicates the ID of a department and its name.
3636
</pre>
3737

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

40-
<p>Find employees who have the highest salary in each of the departments.</p>
40+
<p>Write a solution to find employees who have the highest salary in each of the departments.</p>
4141

4242
<p>Return the result table in <strong>any order</strong>.</p>
4343

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@
1313
| id | int |
1414
| email | varchar |
1515
+-------------+---------+
16-
In SQL, id is the primary key column for this table.
16+
id is the primary key (column with unique values) for this table.
1717
Each row of this table contains an email. The emails will not contain uppercase letters.
1818
</pre>
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>.</p>
22+
<p>Write a solution to<strong> delete</strong> all duplicate emails, keeping only one unique email with the smallest <code>id</code>.</p>
2323

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

solution/0100-0199/0197.Rising Temperature/README.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,20 @@
1818
| recordDate | date |
1919
| temperature | int |
2020
+---------------+---------+
21-
id 是这个表的主键
21+
在 SQL 中,id 是该表的主键。
2222
该表包含特定日期的温度信息</pre>
2323

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

26-
<p>编写一个 SQL 查询,来查找与之前(昨天的)日期相比温度更高的所有日期的 <code>id</code> 。</p>
26+
<p>找出与之前(昨天的)日期相比温度更高的所有日期的 <code>id</code> 。</p>
2727

28-
<p>返回结果 <strong>不要求顺序</strong> 。</p>
28+
<p>返回结果 <strong>无顺序要求</strong> 。</p>
2929

30-
<p>查询结果格式如下例。</p>
30+
<p>结果格式如下例子所示。</p>
3131

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

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

3636
<pre>
3737
<code><strong>输入:</strong>

solution/0300-0399/0399.Evaluate Division/README.md

+13-11
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,11 @@
1414

1515
<p><strong>注意:</strong>输入总是有效的。你可以假设除法运算中不会出现除数为 0 的情况,且不存在任何矛盾的结果。</p>
1616

17-
<p> </p>
17+
<p><strong>注意:</strong>未在等式列表中出现的变量是未定义的,因此无法确定它们的答案。</p>
1818

19-
<p><strong>示例 1:</strong></p>
19+
<p>&nbsp;</p>
20+
21+
<p><strong class="example">示例 1:</strong></p>
2022

2123
<pre>
2224
<strong>输入:</strong>equations = [["a","b"],["b","c"]], values = [2.0,3.0], queries = [["a","c"],["b","a"],["a","e"],["a","a"],["x","x"]]
@@ -25,35 +27,35 @@
2527
条件:<em>a / b = 2.0</em>, <em>b / c = 3.0</em>
2628
问题:<em>a / c = ?</em>, <em>b / a = ?</em>, <em>a / e = ?</em>, <em>a / a = ?</em>, <em>x / x = ?</em>
2729
结果:[6.0, 0.5, -1.0, 1.0, -1.0 ]
28-
</pre>
30+
注意:x 是未定义的 =&gt; -1.0</pre>
2931

30-
<p><strong>示例 2:</strong></p>
32+
<p><strong class="example">示例 2:</strong></p>
3133

3234
<pre>
3335
<strong>输入:</strong>equations = [["a","b"],["b","c"],["bc","cd"]], values = [1.5,2.5,5.0], queries = [["a","c"],["c","b"],["bc","cd"],["cd","bc"]]
3436
<strong>输出:</strong>[3.75000,0.40000,5.00000,0.20000]
3537
</pre>
3638

37-
<p><strong>示例 3:</strong></p>
39+
<p><strong class="example">示例 3:</strong></p>
3840

3941
<pre>
4042
<strong>输入:</strong>equations = [["a","b"]], values = [0.5], queries = [["a","b"],["b","a"],["a","c"],["x","y"]]
4143
<strong>输出:</strong>[0.50000,2.00000,-1.00000,-1.00000]
4244
</pre>
4345

44-
<p> </p>
46+
<p>&nbsp;</p>
4547

4648
<p><strong>提示:</strong></p>
4749

4850
<ul>
49-
<li><code>1 <= equations.length <= 20</code></li>
51+
<li><code>1 &lt;= equations.length &lt;= 20</code></li>
5052
<li><code>equations[i].length == 2</code></li>
51-
<li><code>1 <= A<sub>i</sub>.length, B<sub>i</sub>.length <= 5</code></li>
53+
<li><code>1 &lt;= A<sub>i</sub>.length, B<sub>i</sub>.length &lt;= 5</code></li>
5254
<li><code>values.length == equations.length</code></li>
53-
<li><code>0.0 < values[i] <= 20.0</code></li>
54-
<li><code>1 <= queries.length <= 20</code></li>
55+
<li><code>0.0 &lt; values[i] &lt;= 20.0</code></li>
56+
<li><code>1 &lt;= queries.length &lt;= 20</code></li>
5557
<li><code>queries[i].length == 2</code></li>
56-
<li><code>1 <= C<sub>j</sub>.length, D<sub>j</sub>.length <= 5</code></li>
58+
<li><code>1 &lt;= C<sub>j</sub>.length, D<sub>j</sub>.length &lt;= 5</code></li>
5759
<li><code>A<sub>i</sub>, B<sub>i</sub>, C<sub>j</sub>, D<sub>j</sub></code> 由小写英文字母与数字组成</li>
5860
</ul>
5961

solution/0400-0499/0427.Construct Quad Tree/README_EN.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class Node {
5050
<strong>Input:</strong> grid = [[0,1],[1,0]]
5151
<strong>Output:</strong> [[0,1],[1,0],[1,1],[1,1],[1,0]]
5252
<strong>Explanation:</strong> The explanation of this example is shown below:
53-
Notice that 0 represnts False and 1 represents True in the photo representing the Quad-Tree.
53+
Notice that 0 represents False and 1 represents True in the photo representing the Quad-Tree.
5454
<img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/0400-0499/0427.Construct%20Quad%20Tree/images/e1tree.png" style="width: 777px; height: 186px;" />
5555
</pre>
5656

solution/0500-0599/0511.Game Play Analysis I/README_EN.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@
1515
| event_date | date |
1616
| games_played | int |
1717
+--------------+---------+
18-
In SQL, (player_id, event_date) is the primary key of this table.
18+
(player_id, event_date) is the primary key (combination of columns with unique values) of this table.
1919
This table shows the activity of players of some games.
2020
Each row is a record of a player who logged in and played a number of games (possibly 0) before logging out on someday using some device.
2121
</pre>
2222

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

25-
<p>Find the <strong>first login date</strong> for each player.</p>
25+
<p>Write a solution to find the <strong>first login date</strong> for each player.</p>
2626

2727
<p>Return the result table in <strong>any order</strong>.</p>
2828

solution/0500-0599/0512.Game Play Analysis II/README_EN.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,18 @@
1515
| event_date | date |
1616
| games_played | int |
1717
+--------------+---------+
18-
(player_id, event_date) is the primary key of this table.
18+
(player_id, event_date) is the primary key (combination of columns with unique values) of this table.
1919
This table shows the activity of players of some games.
2020
Each row is a record of a player who logged in and played a number of games (possibly 0) before logging out on someday using some device.
2121
</pre>
2222

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

25-
<p>Write an SQL query to report the <strong>device</strong> that is first logged in for each player.</p>
25+
<p>Write a solution to report the <strong>device</strong> that is first logged in for each player.</p>
2626

2727
<p>Return the result table in <strong>any order</strong>.</p>
2828

29-
<p>The query result format is in the following example.</p>
29+
<p>The&nbsp;result format is in the following example.</p>
3030

3131
<p>&nbsp;</p>
3232
<p><strong class="example">Example 1:</strong></p>

solution/0500-0599/0570.Managers with at Least 5 Direct Reports/README_EN.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@
1515
| department | varchar |
1616
| managerId | int |
1717
+-------------+---------+
18-
In SQL, id is the primary key column for this table.
18+
id is the primary key (column with unique values) for this table.
1919
Each row of this table indicates the name of an employee, their department, and the id of their manager.
2020
If managerId is null, then the employee does not have a manager.
2121
No employee will be the manager of themself.
2222
</pre>
2323

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

26-
<p>Find the managers with at least <strong>five direct reports</strong>.</p>
26+
<p>Write a solution to find managers with at least <strong>five direct reports</strong>.</p>
2727

2828
<p>Return the result table in <strong>any order</strong>.</p>
2929

solution/0500-0599/0584.Find Customer Referee/README.md

+34-18
Original file line numberDiff line numberDiff line change
@@ -6,35 +6,51 @@
66

77
<!-- 这里写题目描述 -->
88

9-
<p>给定表 <code>customer</code> ,里面保存了所有客户信息和他们的推荐人。</p>
9+
<p>表:&nbsp;<code>Customer</code></p>
1010

1111
<pre>
12-
+------+------+-----------+
13-
| id | name | referee_id|
14-
+------+------+-----------+
15-
| 1 | Will | NULL |
16-
| 2 | Jane | NULL |
17-
| 3 | Alex | 2 |
18-
| 4 | Bill | NULL |
19-
| 5 | Zack | 1 |
20-
| 6 | Mark | 2 |
21-
+------+------+-----------+
22-
</pre>
23-
24-
<p>写一个查询语句,返回一个客户列表,列表中客户的推荐人的编号都 <strong>不是 </strong>2。</p>
25-
26-
<p>对于上面的示例数据,结果为:</p>
12+
+-------------+---------+
13+
| Column Name | Type |
14+
+-------------+---------+
15+
| id | int |
16+
| name | varchar |
17+
| referee_id | int |
18+
+-------------+---------+
19+
在 SQL 中,id 是该表的主键列。
20+
该表的每一行表示一个客户的 id、姓名以及推荐他们的客户的 id。</pre>
21+
22+
<p>找出那些 <strong>没有被</strong> <code>id = 2</code> 的客户 <strong>推荐</strong> 的客户的姓名。</p>
23+
24+
<p>以 <strong>任意顺序</strong> 返回结果表。</p>
25+
26+
<p>结果格式如下所示。</p>
27+
28+
<p>&nbsp;</p>
29+
30+
<p><strong>示例 1:</strong></p>
2731

2832
<pre>
33+
<b>输入:</b>
34+
Customer 表:
35+
+----+------+------------+
36+
| id | name | referee_id |
37+
+----+------+------------+
38+
| 1 | Will | null |
39+
| 2 | Jane | null |
40+
| 3 | Alex | 2 |
41+
| 4 | Bill | null |
42+
| 5 | Zack | 1 |
43+
| 6 | Mark | 2 |
44+
+----+------+------------+
45+
<b>输出:</b>
2946
+------+
3047
| name |
3148
+------+
3249
| Will |
3350
| Jane |
3451
| Bill |
3552
| Zack |
36-
+------+
37-
</pre>
53+
+------+</pre>
3854

3955
## 解法
4056

0 commit comments

Comments
 (0)