Skip to content

Commit ce92293

Browse files
authored
feat: update lc problems and solutions (#1136)
1 parent 7aeedec commit ce92293

File tree

69 files changed

+1282
-658
lines changed

Some content is hidden

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

69 files changed

+1282
-658
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ Each row of this table contains information about the salary of an employee.
1919

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

22-
<p>Write an SQL query to report the second highest salary from the <code>Employee</code> table. If there is no second highest salary, the query should report <code>null</code>.</p>
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</code>.</p>
2323

24-
<p>The query result format is in the following example.</p>
24+
<p>The result format is in the following example.</p>
2525

2626
<p>&nbsp;</p>
2727
<p><strong class="example">Example 1:</strong></p>

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ Each row of this table contains information about the salary of an employee.
1919

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

22-
<p>Write an SQL query to report 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, the query should report <code>null</code>.</p>
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>
2323

24-
<p>The query result format is in the following example.</p>
24+
<p>The result format is in the following example.</p>
2525

2626
<p>&nbsp;</p>
2727
<p><strong class="example">Example 1:</strong></p>

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Each row of this table contains the score of a game. Score is a floating point v
1919

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

22-
<p>Write an SQL query to rank the scores. The ranking should be calculated according to the following rules:</p>
22+
<p>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>
@@ -29,7 +29,7 @@ Each row of this table contains the score of a game. Score is a floating point v
2929

3030
<p>Return the result table ordered by <code>score</code> in descending order.</p>
3131

32-
<p>The query result format is in the following example.</p>
32+
<p>The result format is in the following example.</p>
3333

3434
<p>&nbsp;</p>
3535
<p><strong class="example">Example 1:</strong></p>

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@ Each row of this table indicates the ID of an order and the ID of the customer w
3535

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

38-
<p>Write an SQL query to report all customers who never order anything.</p>
38+
<p>Find all customers who never order anything.</p>
3939

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

42-
<p>The query result format is in the following example.</p>
42+
<p>The result format is in the following example.</p>
4343

4444
<p>&nbsp;</p>
4545
<p><strong class="example">Example 1:</strong></p>

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,11 @@ Each row of this table indicates the ID of a department and its name.
3737

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

40-
<p>Write an SQL query to find employees who have the highest salary in each of the departments.</p>
40+
<p>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

44-
<p>The query result format is in the following example.</p>
44+
<p>The result format is in the following example.</p>
4545

4646
<p>&nbsp;</p>
4747
<p><strong class="example">Example 1:</strong></p>

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ Each row of this table contains an email. The emails will not contain uppercase
1919

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

22-
<p>Write an SQL query to <strong>delete</strong> all the duplicate emails, keeping only one unique email with the smallest <code>id</code>. 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>. (For SQL users, please note that you are supposed to write a <code>DELETE</code> statement and not a <code>SELECT</code> one.)</p>
2323

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

26-
<p>The query result format is in the following example.</p>
26+
<p>The result format is in the following example.</p>
2727

2828
<p>&nbsp;</p>
2929
<p><strong class="example">Example 1:</strong></p>

solution/0300-0399/0304.Range Sum Query 2D - Immutable/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ public:
175175
*/
176176
177177
struct NumMatrix {
178-
// Of size (N + 1) * (M + 1)
178+
// Of size (N + 1) * (M + 1)
179179
prefix_vec: Vec<Vec<i32>>,
180180
n: usize,
181181
m: usize,
@@ -184,22 +184,22 @@ struct NumMatrix {
184184
}
185185
186186
187-
/**
187+
/**
188188
* `&self` means the method takes an immutable reference.
189189
* If you need a mutable reference, change it to `&mut self` instead.
190190
*/
191191
impl NumMatrix {
192192
193193
fn new(matrix: Vec<Vec<i32>>) -> Self {
194-
NumMatrix {
194+
NumMatrix {
195195
prefix_vec: vec![vec![0; matrix[0].len() + 1]; matrix.len() + 1],
196196
n: matrix.len(),
197197
m: matrix[0].len(),
198198
is_initialized: false,
199199
ref_vec: matrix,
200200
}
201201
}
202-
202+
203203
fn sum_region(&mut self, row1: i32, col1: i32, row2: i32, col2: i32) -> i32 {
204204
if !self.is_initialized {
205205
self.initialize_prefix_vec();

solution/0300-0399/0304.Range Sum Query 2D - Immutable/README_EN.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ numMatrix.sumRegion(1, 2, 2, 4); // return 12 (i.e sum of the blue rectangle)
5252

5353
## Solutions
5454

55-
We use $s[i + 1][j + 1]$ to represent the sum of all elements in the upper-left part up to the $i$-th row and $j$-th column, where the indices $i$ and $j$ both start from $0$.
55+
We use $s[i + 1][j + 1]$ to represent the sum of all elements in the upper-left part up to the $i$-th row and $j$-th column, where the indices $i$ and $j$ both start from $0$.
5656

5757
We can derive the following prefix sum formula:
5858

@@ -166,7 +166,7 @@ public:
166166
*/
167167
168168
struct NumMatrix {
169-
// Of size (N + 1) * (M + 1)
169+
// Of size (N + 1) * (M + 1)
170170
prefix_vec: Vec<Vec<i32>>,
171171
n: usize,
172172
m: usize,
@@ -175,22 +175,22 @@ public:
175175
}
176176
177177
178-
/**
178+
/**
179179
* `&self` means the method takes an immutable reference.
180180
* If you need a mutable reference, change it to `&mut self` instead.
181181
*/
182182
impl NumMatrix {
183183
184184
fn new(matrix: Vec<Vec<i32>>) -> Self {
185-
NumMatrix {
185+
NumMatrix {
186186
prefix_vec: vec![vec![0; matrix[0].len() + 1]; matrix.len() + 1],
187187
n: matrix.len(),
188188
m: matrix[0].len(),
189189
is_initialized: false,
190190
ref_vec: matrix,
191191
}
192192
}
193-
193+
194194
fn sum_region(&mut self, row1: i32, col1: i32, row2: i32, col2: i32) -> i32 {
195195
if !self.is_initialized {
196196
self.initialize_prefix_vec();

solution/0300-0399/0373.Find K Pairs with Smallest Sums/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@
66

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

9-
<p>给定两个以 <strong>升序排列</strong> 的整数数组 <code>nums1</code> 和<strong> </strong><code>nums2</code><strong>&nbsp;</strong>,&nbsp;以及一个整数 <code>k</code><strong>&nbsp;</strong>。</p>
9+
<p>给定两个以 <strong>非递减顺序排列</strong> 的整数数组 <code>nums1</code> 和<strong> </strong><code>nums2</code><strong>&nbsp;</strong>,&nbsp;以及一个整数 <code>k</code><strong>&nbsp;</strong>。</p>
1010

1111
<p>定义一对值&nbsp;<code>(u,v)</code>,其中第一个元素来自&nbsp;<code>nums1</code>,第二个元素来自 <code>nums2</code><strong>&nbsp;</strong>。</p>
1212

1313
<p>请找到和最小的 <code>k</code>&nbsp;个数对&nbsp;<code>(u<sub>1</sub>,v<sub>1</sub>)</code>, <code>&nbsp;(u<sub>2</sub>,v<sub>2</sub>)</code> &nbsp;... &nbsp;<code>(u<sub>k</sub>,v<sub>k</sub>)</code>&nbsp;。</p>
1414

1515
<p>&nbsp;</p>
1616

17-
<p><strong>示例 1:</strong></p>
17+
<p><strong class="example">示例 1:</strong></p>
1818

1919
<pre>
2020
<strong>输入:</strong> nums1 = [1,7,11], nums2 = [2,4,6], k = 3
@@ -23,7 +23,7 @@
2323
[1,2],[1,4],[1,6],[7,2],[7,4],[11,2],[7,6],[11,4],[11,6]
2424
</pre>
2525

26-
<p><strong>示例 2:</strong></p>
26+
<p><strong class="example">示例 2:</strong></p>
2727

2828
<pre>
2929
<strong>输入: </strong>nums1 = [1,1,2], nums2 = [1,2,3], k = 2
@@ -32,7 +32,7 @@
3232
&nbsp; [1,1],[1,1],[1,2],[2,1],[1,2],[2,2],[1,3],[1,3],[2,3]
3333
</pre>
3434

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

3737
<pre>
3838
<strong>输入: </strong>nums1 = [1,2], nums2 = [3], k = 3

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ Each row is a record of a player who logged in and played a number of games (pos
2222

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

25-
<p>Write an SQL query to report the <strong>first login date</strong> for each player.</p>
25+
<p>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

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

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

0 commit comments

Comments
 (0)