Skip to content

Commit dc30052

Browse files
committed
feat: update lc problems
1 parent 86b6841 commit dc30052

File tree

18 files changed

+97
-61
lines changed

18 files changed

+97
-61
lines changed

solution/0000-0099/0020.Valid Parentheses/README_EN.md

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
<ol>
1212
<li>Open brackets must be closed by the same type of brackets.</li>
1313
<li>Open brackets must be closed in the correct order.</li>
14+
<li>Every close bracket has a corresponding open bracket of the same type.</li>
1415
</ol>
1516

1617
<p>&nbsp;</p>

solution/0000-0099/0031.Next Permutation/README_EN.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<p>A <strong>permutation</strong> of an array of integers is an arrangement of its members into a sequence or linear order.</p>
88

99
<ul>
10-
<li>For example, for <code>arr = [1,2,3]</code>, the following are considered permutations of <code>arr</code>: <code>[1,2,3]</code>, <code>[1,3,2]</code>, <code>[3,1,2]</code>, <code>[2,3,1]</code>.</li>
10+
<li>For example, for <code>arr = [1,2,3]</code>, the following are all the permutations of <code>arr</code>: <code>[1,2,3], [1,3,2], [2, 1, 3], [2, 3, 1], [3,1,2], [3,2,1]</code>.</li>
1111
</ul>
1212

1313
<p>The <strong>next permutation</strong> of an array of integers is the next lexicographically greater permutation of its integer. More formally, if all the permutations of the array are sorted in one container according to their lexicographical order, then the <strong>next permutation</strong> of that array is the permutation that follows it in the sorted container. If such arrangement is not possible, the array must be rearranged as the lowest possible order (i.e., sorted in ascending order).</p>

solution/0200-0299/0234.Palindrome Linked List/README_EN.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
## Description
66

7-
<p>Given the <code>head</code> of a singly linked list, return <code>true</code> if it is a palindrome.</p>
7+
<p>Given the <code>head</code> of a singly linked list, return <code>true</code><em> if it is a palindrome or </em><code>false</code><em> otherwise</em>.</p>
88

99
<p>&nbsp;</p>
1010
<p><strong>Example 1:</strong></p>

solution/0300-0399/0326.Power of Three/README_EN.md

+5-2
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,23 @@
1414
<pre>
1515
<strong>Input:</strong> n = 27
1616
<strong>Output:</strong> true
17+
<strong>Explanation:</strong> 27 = 3<sup>3</sup>
1718
</pre>
1819

1920
<p><strong>Example 2:</strong></p>
2021

2122
<pre>
2223
<strong>Input:</strong> n = 0
2324
<strong>Output:</strong> false
25+
<strong>Explanation:</strong> There is no x where 3<sup>x</sup> = 0.
2426
</pre>
2527

2628
<p><strong>Example 3:</strong></p>
2729

2830
<pre>
29-
<strong>Input:</strong> n = 9
30-
<strong>Output:</strong> true
31+
<strong>Input:</strong> n = -1
32+
<strong>Output:</strong> false
33+
<strong>Explanation:</strong> There is no x where 3<sup>x</sup> = (-1).
3134
</pre>
3235

3336
<p>&nbsp;</p>

solution/0400-0499/0493.Reverse Pairs/README_EN.md

+17-3
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,26 @@
1010

1111
<p>&nbsp;</p>
1212
<p><strong>Example 1:</strong></p>
13-
<pre><strong>Input:</strong> nums = [1,3,2,3,1]
13+
14+
<pre>
15+
<strong>Input:</strong> nums = [1,3,2,3,1]
1416
<strong>Output:</strong> 2
15-
</pre><p><strong>Example 2:</strong></p>
16-
<pre><strong>Input:</strong> nums = [2,4,3,5,1]
17+
<strong>Explanation:</strong> The reverse pairs are:
18+
(1, 4) --&gt; nums[1] = 3, nums[4] = 1, 3 &gt; 2 * 1
19+
(3, 4) --&gt; nums[3] = 3, nums[4] = 1, 3 &gt; 2 * 1
20+
</pre>
21+
22+
<p><strong>Example 2:</strong></p>
23+
24+
<pre>
25+
<strong>Input:</strong> nums = [2,4,3,5,1]
1726
<strong>Output:</strong> 3
27+
<strong>Explanation:</strong> The reverse pairs are:
28+
(1, 4) --&gt; nums[1] = 4, nums[4] = 1, 4 &gt; 2 * 1
29+
(2, 4) --&gt; nums[2] = 3, nums[4] = 1, 3 &gt; 2 * 1
30+
(3, 4) --&gt; nums[3] = 3, nums[4] = 1, 5 &gt; 2 * 1
1831
</pre>
32+
1933
<p>&nbsp;</p>
2034
<p><strong>Constraints:</strong></p>
2135

solution/0500-0599/0569.Median Employee Salary/README_EN.md

+34-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Each row of this table indicates the company and the salary of one employee.
2020

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

23-
<p>Write an SQL query to find the median salary of each company.</p>
23+
<p>Write an SQL query to find the rows that contain the median salary of each company. While calculating the median, when you sort the salaries of the company, break the ties by <code>id</code>.</p>
2424

2525
<p>Return the result table in <strong>any order</strong>.</p>
2626

@@ -63,6 +63,39 @@ Employee table:
6363
| 9 | B | 1154 |
6464
| 14 | C | 2645 |
6565
+----+---------+--------+
66+
<strong>Explanation:</strong>
67+
For company A, the rows sorted are as follows:
68+
+----+---------+--------+
69+
| id | company | salary |
70+
+----+---------+--------+
71+
| 3 | A | 15 |
72+
| 2 | A | 341 |
73+
| 5 | A | 451 | &lt;-- median
74+
| 6 | A | 513 | &lt;-- median
75+
| 1 | A | 2341 |
76+
| 4 | A | 15314 |
77+
+----+---------+--------+
78+
For company B, the rows sorted are as follows:
79+
+----+---------+--------+
80+
| id | company | salary |
81+
+----+---------+--------+
82+
| 8 | B | 13 |
83+
| 7 | B | 15 |
84+
| 12 | B | 234 | &lt;-- median
85+
| 11 | B | 1221 | &lt;-- median
86+
| 9 | B | 1154 |
87+
| 10 | B | 1345 |
88+
+----+---------+--------+
89+
For company C, the rows sorted are as follows:
90+
+----+---------+--------+
91+
| id | company | salary |
92+
+----+---------+--------+
93+
| 17 | C | 65 |
94+
| 13 | C | 2345 |
95+
| 14 | C | 2645 | &lt;-- median
96+
| 15 | C | 2645 |
97+
| 16 | C | 2652 |
98+
+----+---------+--------+
6699
</pre>
67100

68101
<p>&nbsp;</p>

solution/0500-0599/0599.Minimum Index Sum of Two Lists/README_EN.md

+22-6
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,41 @@
44

55
## Description
66

7-
<p>Suppose Andy and Doris want to choose a restaurant for dinner, and they both have a list of favorite restaurants represented by strings.</p>
7+
<p>Given two arrays of strings <code>list1</code> and <code>list2</code>, find the <strong>common strings with the least index sum</strong>.</p>
88

9-
<p>You need to help them find out their <b>common interest</b> with the <b>least list index sum</b>. If there is a choice tie between answers, output all of them with no order requirement. You could assume there always exists an answer.</p>
9+
<p>A <strong>common string</strong> is a string that appeared in both <code>list1</code> and <code>list2</code>.</p>
10+
11+
<p>A <strong>common string with the least index sum</strong> is a common string such that if it appeared at <code>list1[i]</code> and <code>list2[j]</code> then <code>i + j</code> should be the minimum value among all the other <strong>common strings</strong>.</p>
12+
13+
<p>Return <em>all the <strong>common strings with the least index sum</strong></em>. Return the answer in <strong>any order</strong>.</p>
1014

1115
<p>&nbsp;</p>
1216
<p><strong>Example 1:</strong></p>
1317

1418
<pre>
1519
<strong>Input:</strong> list1 = [&quot;Shogun&quot;,&quot;Tapioca Express&quot;,&quot;Burger King&quot;,&quot;KFC&quot;], list2 = [&quot;Piatti&quot;,&quot;The Grill at Torrey Pines&quot;,&quot;Hungry Hunter Steakhouse&quot;,&quot;Shogun&quot;]
1620
<strong>Output:</strong> [&quot;Shogun&quot;]
17-
<strong>Explanation:</strong> The only restaurant they both like is &quot;Shogun&quot;.
21+
<strong>Explanation:</strong> The only common string is &quot;Shogun&quot;.
1822
</pre>
1923

2024
<p><strong>Example 2:</strong></p>
2125

2226
<pre>
2327
<strong>Input:</strong> list1 = [&quot;Shogun&quot;,&quot;Tapioca Express&quot;,&quot;Burger King&quot;,&quot;KFC&quot;], list2 = [&quot;KFC&quot;,&quot;Shogun&quot;,&quot;Burger King&quot;]
2428
<strong>Output:</strong> [&quot;Shogun&quot;]
25-
<strong>Explanation:</strong> The restaurant they both like and have the least index sum is &quot;Shogun&quot; with index sum 1 (0+1).
29+
<strong>Explanation:</strong> The common string with the least index sum is &quot;Shogun&quot; with index sum = (0 + 1) = 1.
30+
</pre>
31+
32+
<p><strong>Example 3:</strong></p>
33+
34+
<pre>
35+
<strong>Input:</strong> list1 = [&quot;happy&quot;,&quot;sad&quot;,&quot;good&quot;], list2 = [&quot;sad&quot;,&quot;happy&quot;,&quot;good&quot;]
36+
<strong>Output:</strong> [&quot;sad&quot;,&quot;happy&quot;]
37+
<strong>Explanation:</strong> There are three common strings:
38+
&quot;happy&quot; with index sum = (0 + 1) = 1.
39+
&quot;sad&quot; with index sum = (1 + 0) = 1.
40+
&quot;good&quot; with index sum = (2 + 2) = 4.
41+
The strings with the least index sum are &quot;sad&quot; and &quot;happy&quot;.
2642
</pre>
2743

2844
<p>&nbsp;</p>
@@ -32,8 +48,8 @@
3248
<li><code>1 &lt;= list1.length, list2.length &lt;= 1000</code></li>
3349
<li><code>1 &lt;= list1[i].length, list2[i].length &lt;= 30</code></li>
3450
<li><code>list1[i]</code> and <code>list2[i]</code> consist of spaces <code>&#39; &#39;</code> and English letters.</li>
35-
<li>All the stings of <code>list1</code> are <strong>unique</strong>.</li>
36-
<li>All the stings of <code>list2</code>&nbsp;are <strong>unique</strong>.</li>
51+
<li>All the strings of <code>list1</code> are <strong>unique</strong>.</li>
52+
<li>All the strings of <code>list2</code> are <strong>unique</strong>.</li>
3753
</ul>
3854

3955
## Solutions

solution/0600-0699/0662.Maximum Width of Binary Tree/README_EN.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ class Solution:
9494
ans = max(ans, i - t[depth] + 1)
9595
dfs(root.left, depth + 1, i << 1)
9696
dfs(root.right, depth + 1, i << 1 | 1)
97-
97+
9898
ans = 1
9999
t = []
100100
dfs(root, 0, 1)

solution/0800-0899/0871.Minimum Number of Refueling Stops/README_EN.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ We made 2 refueling stops along the way, so we return 2.
4949
<ul>
5050
<li><code>1 &lt;= target, startFuel &lt;= 10<sup>9</sup></code></li>
5151
<li><code>0 &lt;= stations.length &lt;= 500</code></li>
52-
<li><code>0 &lt;= position<sub>i</sub> &lt;= position<sub>i+1</sub> &lt; target</code></li>
52+
<li><code>1 &lt;= position<sub>i</sub> &lt; position<sub>i+1</sub> &lt; target</code></li>
5353
<li><code>1 &lt;= fuel<sub>i</sub> &lt; 10<sup>9</sup></code></li>
5454
</ul>
5555

solution/1300-1399/1372.Longest ZigZag Path in a Binary Tree/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ public:
149149

150150
int longestZigZag(TreeNode* root) {
151151
dfs(root, 0, 0);
152-
return ans;
152+
return ans;
153153
}
154154

155155
void dfs(TreeNode* root, int l, int r) {

solution/1300-1399/1372.Longest ZigZag Path in a Binary Tree/README_EN.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ public:
136136

137137
int longestZigZag(TreeNode* root) {
138138
dfs(root, 0, 0);
139-
return ans;
139+
return ans;
140140
}
141141

142142
void dfs(TreeNode* root, int l, int r) {

solution/1400-1499/1424.Diagonal Traverse II/README.md

-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@
6565

6666
时间复杂度 $O(n\log n)$,其中 $n$ 是 `nums` 数组元素的个数。
6767

68-
6968
<!-- tabs:start -->
7069

7170
### **Python3**

solution/1400-1499/1424.Diagonal Traverse II/README_EN.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ class Solution {
5757
for (int i = 0; i < nums.size(); ++i) {
5858
for (int j = 0; j < nums.get(i).size(); ++j) {
5959
arr.add(new int[]{i + j, j, nums.get(i).get(j)});
60-
}
60+
}
6161
}
6262
arr.sort((a, b) -> a[0] == b[0] ? a[1] - b[1] : a[0] - b[0]);
6363
int[] ans = new int[arr.size()];

solution/1400-1499/1494.Parallel Courses II/README_EN.md

+7-18
Original file line numberDiff line numberDiff line change
@@ -12,39 +12,28 @@
1212

1313
<p>&nbsp;</p>
1414
<p><strong>Example 1:</strong></p>
15-
16-
<p><strong><img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/1400-1499/1494.Parallel%20Courses%20II/images/leetcode_parallel_courses_1.png" style="width: 300px; height: 164px;" /></strong></p>
17-
15+
<img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/1400-1499/1494.Parallel%20Courses%20II/images/leetcode_parallel_courses_1.png" style="width: 269px; height: 147px;" />
1816
<pre>
19-
<strong>Input:</strong> n = 4, dependencies = [[2,1],[3,1],[1,4]], k = 2
20-
<strong>Output:</strong> 3
17+
<strong>Input:</strong> n = 4, relations = [[2,1],[3,1],[1,4]], k = 2
18+
<strong>Output:</strong> 3
2119
<strong>Explanation:</strong> The figure above represents the given graph.
2220
In the first semester, you can take courses 2 and 3.
2321
In the second semester, you can take course 1.
2422
In the third semester, you can take course 4.
2523
</pre>
2624

2725
<p><strong>Example 2:</strong></p>
28-
29-
<p><strong><img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/1400-1499/1494.Parallel%20Courses%20II/images/leetcode_parallel_courses_2.png" style="width: 300px; height: 234px;" /></strong></p>
30-
26+
<img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/1400-1499/1494.Parallel%20Courses%20II/images/leetcode_parallel_courses_2.png" style="width: 271px; height: 211px;" />
3127
<pre>
32-
<strong>Input:</strong> n = 5, dependencies = [[2,1],[3,1],[4,1],[1,5]], k = 2
33-
<strong>Output:</strong> 4
28+
<strong>Input:</strong> n = 5, relations = [[2,1],[3,1],[4,1],[1,5]], k = 2
29+
<strong>Output:</strong> 4
3430
<strong>Explanation:</strong> The figure above represents the given graph.
35-
In the first semester, you can take courses 2 and 3 only since you cannot take more than two per semester.
31+
In the first semester, you can only take courses 2 and 3 since you cannot take more than two per semester.
3632
In the second semester, you can take course 4.
3733
In the third semester, you can take course 1.
3834
In the fourth semester, you can take course 5.
3935
</pre>
4036

41-
<p><strong>Example 3:</strong></p>
42-
43-
<pre>
44-
<strong>Input:</strong> n = 11, dependencies = [], k = 2
45-
<strong>Output:</strong> 6
46-
</pre>
47-
4837
<p>&nbsp;</p>
4938
<p><strong>Constraints:</strong></p>
5039

solution/1700-1799/1712.Ways to Split Array Into Three Subarrays/README_EN.md

+4-21
Original file line numberDiff line numberDiff line change
@@ -7,61 +7,44 @@
77
<p>A split of an integer array is <strong>good</strong> if:</p>
88

99
<ul>
10-
<li>The array is split into three <strong>non-empty</strong> contiguous subarrays - named <code>left</code>, <code>mid</code>, <code>right</code> respectively from left to right.</li>
11-
<li>The sum of the elements in <code>left</code> is less than or equal to the sum of the elements in <code>mid</code>, and the sum of the elements in <code>mid</code> is less than or equal to the sum of the elements in <code>right</code>.</li>
12-
10+
<li>The array is split into three <strong>non-empty</strong> contiguous subarrays - named <code>left</code>, <code>mid</code>, <code>right</code> respectively from left to right.</li>
11+
<li>The sum of the elements in <code>left</code> is less than or equal to the sum of the elements in <code>mid</code>, and the sum of the elements in <code>mid</code> is less than or equal to the sum of the elements in <code>right</code>.</li>
1312
</ul>
1413

1514
<p>Given <code>nums</code>, an array of <strong>non-negative</strong> integers, return <em>the number of <strong>good</strong> ways to split</em> <code>nums</code>. As the number may be too large, return it <strong>modulo</strong> <code>10<sup>9 </sup>+ 7</code>.</p>
1615

1716
<p>&nbsp;</p>
18-
1917
<p><strong>Example 1:</strong></p>
2018

2119
<pre>
22-
2320
<strong>Input:</strong> nums = [1,1,1]
24-
2521
<strong>Output:</strong> 1
26-
2722
<strong>Explanation:</strong> The only good way to split nums is [1] [1] [1].</pre>
2823

2924
<p><strong>Example 2:</strong></p>
3025

3126
<pre>
32-
3327
<strong>Input:</strong> nums = [1,2,2,2,5,0]
34-
3528
<strong>Output:</strong> 3
36-
3729
<strong>Explanation:</strong> There are three good ways of splitting nums:
38-
3930
[1] [2] [2,2,5,0]
40-
4131
[1] [2,2] [2,5,0]
42-
4332
[1,2] [2,2] [5,0]
44-
4533
</pre>
4634

4735
<p><strong>Example 3:</strong></p>
4836

4937
<pre>
50-
5138
<strong>Input:</strong> nums = [3,2,1]
52-
5339
<strong>Output:</strong> 0
54-
5540
<strong>Explanation:</strong> There is no good way to split nums.</pre>
5641

5742
<p>&nbsp;</p>
58-
5943
<p><strong>Constraints:</strong></p>
6044

6145
<ul>
62-
<li><code>3 &lt;= nums.length &lt;= 10<sup>5</sup></code></li>
63-
<li><code>0 &lt;= nums[i] &lt;= 10<sup>4</sup></code></li>
64-
46+
<li><code>3 &lt;= nums.length &lt;= 10<sup>5</sup></code></li>
47+
<li><code>0 &lt;= nums[i] &lt;= 10<sup>4</sup></code></li>
6548
</ul>
6649

6750
## Solutions

solution/2300-2399/2388.Change Null Values in a Table to the Previous Value/README.md

-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ For ID 2, the previous value that is not null is from ID 1. We replace the null
6161
Note that the rows in the output are the same as in the input.
6262
</pre>
6363

64-
6564
## 解法
6665

6766
<!-- 这里可写通用的实现逻辑 -->

solution/2300-2399/2388.Change Null Values in a Table to the Previous Value/README_EN.md

-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ For ID 2, the previous value that is not null is from ID 1. We replace the null
5959
Note that the rows in the output are the same as in the input.
6060
</pre>
6161

62-
6362
## Solutions
6463

6564
<!-- tabs:start -->

0 commit comments

Comments
 (0)