Skip to content

Commit f5bb05b

Browse files
committed
feat: update lc problems
1 parent f9e7f6d commit f5bb05b

File tree

185 files changed

+8802
-8776
lines changed

Some content is hidden

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

185 files changed

+8802
-8776
lines changed

lcci/17.12.BiNode/README.md

+2-3
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737

3838
[897. 递增顺序查找树](/solution/0800-0899/0897.Increasing%20Order%20Search%20Tree/README.md)
3939

40-
4140
<!-- tabs:start -->
4241

4342
### **Python3**
@@ -86,7 +85,7 @@ class Solution:
8685
*/
8786
class Solution {
8887
private TreeNode prev;
89-
88+
9089
public TreeNode convertBiNode(TreeNode root) {
9190
TreeNode dummy = new TreeNode(0, null, root);
9291
prev = dummy;
@@ -122,7 +121,7 @@ class Solution {
122121
class Solution {
123122
public:
124123
TreeNode* prev;
125-
124+
126125
TreeNode* convertBiNode(TreeNode* root) {
127126
TreeNode* dummy = new TreeNode(0, nullptr, root);
128127
prev = dummy;

lcci/17.12.BiNode/README_EN.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ class Solution:
7676
*/
7777
class Solution {
7878
private TreeNode prev;
79-
79+
8080
public TreeNode convertBiNode(TreeNode root) {
8181
TreeNode dummy = new TreeNode(0, null, root);
8282
prev = dummy;
@@ -112,7 +112,7 @@ class Solution {
112112
class Solution {
113113
public:
114114
TreeNode* prev;
115-
115+
116116
TreeNode* convertBiNode(TreeNode* root) {
117117
TreeNode* dummy = new TreeNode(0, nullptr, root);
118118
prev = dummy;

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,13 @@
6868

6969
遍历括号字符串 `s`
7070

71-
- 遇到左括号时,将右括号压入栈中;
72-
- 遇到右括号时,弹出栈顶元素(若栈为空,直接返回 `false`),判断是否是相等。若不匹配,直接返回 `false`
71+
- 遇到左括号时,将右括号压入栈中;
72+
- 遇到右括号时,弹出栈顶元素(若栈为空,直接返回 `false`),判断是否是相等。若不匹配,直接返回 `false`
7373

7474
也可以选择:
7575

76-
- 遇到左括号时,压入当前的左括号。
77-
- 遇到右括号时,弹出栈顶元素(若栈为空,直接返回 `false`),判断是否是匹配,若不匹配,直接返回 `false`
76+
- 遇到左括号时,压入当前的左括号。
77+
- 遇到右括号时,弹出栈顶元素(若栈为空,直接返回 `false`),判断是否是匹配,若不匹配,直接返回 `false`
7878

7979
> 两者的区别仅限于括号转换时机,一个是在入栈时,一个是在出栈时。
8080

solution/0000-0099/0025.Reverse Nodes in k-Group/README.md

+15-30
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,13 @@
66

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

9-
<p>给你一个链表,每 <em>k </em>个节点一组进行翻转,请你返回翻转后的链表。</p>
9+
<p>给你链表的头节点 <code>head</code> ,每&nbsp;<code>k</code><em>&nbsp;</em>个节点一组进行翻转,请你返回修改后的链表。</p>
1010

11-
<p><em>k </em>是一个正整数,它的值小于或等于链表的长度。</p>
11+
<p><code>k</code> 是一个正整数,它的值小于或等于链表的长度。如果节点总数不是&nbsp;<code>k</code><em>&nbsp;</em>的整数倍,那么请将最后剩余的节点保持原有顺序。</p>
1212

13-
<p>如果节点总数不是 <em>k </em>的整数倍,那么请将最后剩余的节点保持原有顺序。</p>
13+
<p>你不能只是单纯的改变节点内部的值,而是需要实际进行节点交换。</p>
1414

15-
<p><strong>进阶:</strong></p>
16-
17-
<ul>
18-
<li>你可以设计一个只使用常数额外空间的算法来解决此问题吗?</li>
19-
<li><strong>你不能只是单纯的改变节点内部的值</strong>,而是需要实际进行节点交换。</li>
20-
</ul>
21-
22-
<p> </p>
15+
<p>&nbsp;</p>
2316

2417
<p><strong>示例 1:</strong></p>
2518
<img alt="" src="https://cdn.jsdelivr.net/gh/doocs/leetcode@main/solution/0000-0099/0025.Reverse%20Nodes%20in%20k-Group/images/reverse_ex1.jpg" style="width: 542px; height: 222px;" />
@@ -29,36 +22,28 @@
2922
</pre>
3023

3124
<p><strong>示例 2:</strong></p>
32-
<img alt="" src="https://cdn.jsdelivr.net/gh/doocs/leetcode@main/solution/0000-0099/0025.Reverse%20Nodes%20in%20k-Group/images/reverse_ex2.jpg" style="width: 542px; height: 222px;" />
33-
<pre>
34-
<strong>输入:</strong>head = [1,2,3,4,5], k = 3
35-
<strong>输出:</strong>[3,2,1,4,5]
36-
</pre>
3725

38-
<p><strong>示例 3:</strong></p>
26+
<p><img alt="" src="https://cdn.jsdelivr.net/gh/doocs/leetcode@main/solution/0000-0099/0025.Reverse%20Nodes%20in%20k-Group/images/reverse_ex2.jpg" style="width: 542px; height: 222px;" /></p>
3927

4028
<pre>
41-
<strong>输入:</strong>head = [1,2,3,4,5], k = 1
42-
<strong>输出:</strong>[1,2,3,4,5]
29+
<strong>输入:</strong>head = [1,2,3,4,5], k = 3
30+
<strong>输出:</strong>[3,2,1,4,5]
4331
</pre>
4432

45-
<p><strong>示例 4:</strong></p>
46-
47-
<pre>
48-
<strong>输入:</strong>head = [1], k = 1
49-
<strong>输出:</strong>[1]
50-
</pre>
33+
<p>&nbsp;</p>
34+
<strong>提示:</strong>
5135

5236
<ul>
37+
<li>链表中的节点数目为 <code>n</code></li>
38+
<li><code>1 &lt;= k &lt;= n &lt;= 5000</code></li>
39+
<li><code>0 &lt;= Node.val &lt;= 1000</code></li>
5340
</ul>
5441

55-
<p><strong>提示:</strong></p>
42+
<p>&nbsp;</p>
43+
44+
<p><strong>进阶:</strong>你可以设计一个只用 <code>O(1)</code> 额外内存空间的算法解决此问题吗?</p>
5645

5746
<ul>
58-
<li>列表中节点的数量在范围 <code>sz</code> 内</li>
59-
<li><code>1 <= sz <= 5000</code></li>
60-
<li><code>0 <= Node.val <= 1000</code></li>
61-
<li><code>1 <= k <= sz</code></li>
6247
</ul>
6348

6449
## 解法

solution/0000-0099/0041.First Missing Positive/README.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -157,25 +157,25 @@ public:
157157

158158
```c
159159
int firstMissingPositive(int* nums, int numsSize) {
160-
160+
161161
int Max = nums[0], i, *Count;
162-
162+
163163
for(i = 1; i<numsSize; i++){
164164
Max = (Max < nums[i]) ? nums[i] : Max;
165165
}
166-
166+
167167
Count = (int*)calloc(Max+1, sizeof(int));
168168
for(i = 0; i<numsSize; i++){
169169
if(nums[i] > 0){
170170
Count[nums[i]]++;
171171
}
172172
}
173-
173+
174174
i = 1;
175175
while(Count[i] != 0){
176176
i++;
177177
}
178-
178+
179179
return i;
180180
}
181181
```

solution/0000-0099/0041.First Missing Positive/README_EN.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -105,25 +105,25 @@ public:
105105

106106
```c
107107
int firstMissingPositive(int* nums, int numsSize) {
108-
108+
109109
int Max = nums[0], i, *Count;
110-
110+
111111
for(i = 1; i<numsSize; i++){
112112
Max = (Max < nums[i]) ? nums[i] : Max;
113113
}
114-
114+
115115
Count = (int*)calloc(Max+1, sizeof(int));
116116
for(i = 0; i<numsSize; i++){
117117
if(nums[i] > 0){
118118
Count[nums[i]]++;
119119
}
120120
}
121-
121+
122122
i = 1;
123123
while(Count[i] != 0){
124124
i++;
125125
}
126-
126+
127127
return i;
128128
}
129129
```

solution/0100-0199/0122.Best Time to Buy and Sell Stock II/README.md

+19-19
Original file line numberDiff line numberDiff line change
@@ -6,37 +6,37 @@
66

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

9-
<p>给定一个数组 <code>prices</code> ,其中&nbsp;<code>prices[i]</code> 表示股票第 <code>i</code> 天的价格。</p>
9+
<p>给你一个整数数组 <code>prices</code> ,其中&nbsp;<code>prices[i]</code> 表示某支股票第 <code>i</code> 天的价格。</p>
1010

11-
<p>在每一天,你可能会决定购买和/或出售股票。你在任何时候&nbsp;<strong>最多</strong>&nbsp;只能持有 <strong>一股</strong> 股票。你也可以购买它,然后在 <strong>同一天</strong> 出售。<br />
12-
返回 <em>你能获得的 <strong>最大</strong> 利润</em>&nbsp;。</p>
11+
<p>在每一天,你可以决定是否购买和/或出售股票。你在任何时候&nbsp;<strong>最多</strong>&nbsp;只能持有 <strong>一股</strong> 股票。你也可以先购买,然后在 <strong>同一天</strong> 出售。</p>
12+
13+
<p>返回 <em>你能获得的 <strong>最大</strong> 利润</em>&nbsp;。</p>
1314

1415
<p>&nbsp;</p>
1516

16-
<p><strong>示例 1:</strong></p>
17+
<p><strong>示例 1</strong></p>
1718

1819
<pre>
19-
<strong>输入:</strong> prices = [7,1,5,3,6,4]
20-
<strong>输出:</strong> 7
21-
<strong>解释:</strong> 在第 2 天(股票价格 = 1)的时候买入,在第 3 天(股票价格 = 5)的时候卖出, 这笔交易所能获得利润 = 5-1 = 4 。
22-
&nbsp; 随后,在第 4 天(股票价格 = 3)的时候买入,在第 5 天(股票价格 = 6)的时候卖出, 这笔交易所能获得利润 = 6-3 = 3 。
23-
</pre>
20+
<strong>输入</strong>prices = [7,1,5,3,6,4]
21+
<strong>输出</strong>7
22+
<strong>解释</strong>在第 2 天(股票价格 = 1)的时候买入,在第 3 天(股票价格 = 5)的时候卖出, 这笔交易所能获得利润 = 5 - 1 = 4 。
23+
&nbsp; 随后,在第 4 天(股票价格 = 3)的时候买入,在第 5 天(股票价格 = 6)的时候卖出, 这笔交易所能获得利润 = 6 - 3 = 3 。
24+
总利润为 4 + 3 = 7 。</pre>
2425

25-
<p><strong>示例 2:</strong></p>
26+
<p><strong>示例 2</strong></p>
2627

2728
<pre>
28-
<strong>输入:</strong> prices = [1,2,3,4,5]
29-
<strong>输出:</strong> 4
30-
<strong>解释:</strong> 在第 1 天(股票价格 = 1)的时候买入,在第 5 天 (股票价格 = 5)的时候卖出, 这笔交易所能获得利润 = 5-1 = 4 。
31-
&nbsp; 注意你不能在第 1 天和第 2 天接连购买股票,之后再将它们卖出。因为这样属于同时参与了多笔交易,你必须在再次购买前出售掉之前的股票。
32-
</pre>
29+
<strong>输入:</strong>prices = [1,2,3,4,5]
30+
<strong>输出:</strong>4
31+
<strong>解释:</strong>在第 1 天(股票价格 = 1)的时候买入,在第 5 天 (股票价格 = 5)的时候卖出, 这笔交易所能获得利润 = 5 - 1 = 4 。
32+
&nbsp; 总利润为 4 。</pre>
3333

34-
<p><strong>示例&nbsp;3:</strong></p>
34+
<p><strong>示例&nbsp;3</strong></p>
3535

3636
<pre>
37-
<strong>输入:</strong> prices = [7,6,4,3,1]
38-
<strong>输出:</strong> 0
39-
<strong>解释:</strong> 在这种情况下, 没有交易完成, 所以最大利润为 0。</pre>
37+
<strong>输入</strong>prices = [7,6,4,3,1]
38+
<strong>输出</strong>0
39+
<strong>解释</strong>在这种情况下, 交易无法获得正利润,所以不参与交易可以获得最大利润,最大利润为 0 。</pre>
4040

4141
<p>&nbsp;</p>
4242

solution/0100-0199/0169.Majority Element/README.md

+15-10
Original file line numberDiff line numberDiff line change
@@ -6,33 +6,38 @@
66

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

9-
<p>给定一个大小为 <em>n </em>的数组,找到其中的多数元素。多数元素是指在数组中出现次数 <strong>大于</strong> <code>⌊ n/2 ⌋</code> 的元素。</p>
9+
<p>给定一个大小为 <code>n</code><em> </em>的数组&nbsp;<code>nums</code> ,返回其中的多数元素。多数元素是指在数组中出现次数 <strong>大于</strong>&nbsp;<code>⌊ n/2 ⌋</code>&nbsp;的元素。</p>
1010

1111
<p>你可以假设数组是非空的,并且给定的数组总是存在多数元素。</p>
1212

13-
<p> </p>
13+
<p>&nbsp;</p>
1414

15-
<p><strong>示例 1:</strong></p>
15+
<p><strong>示例&nbsp;1:</strong></p>
1616

1717
<pre>
18-
<strong>输入:</strong>[3,2,3]
18+
<strong>输入:</strong>nums = [3,2,3]
1919
<strong>输出:</strong>3</pre>
2020

21-
<p><strong>示例 2:</strong></p>
21+
<p><strong>示例&nbsp;2:</strong></p>
2222

2323
<pre>
24-
<strong>输入:</strong>[2,2,1,1,1,2,2]
24+
<strong>输入:</strong>nums = [2,2,1,1,1,2,2]
2525
<strong>输出:</strong>2
2626
</pre>
2727

28-
<p> </p>
29-
30-
<p><strong>进阶:</strong></p>
28+
<p>&nbsp;</p>
29+
<strong>提示:</strong>
3130

3231
<ul>
33-
<li>尝试设计时间复杂度为 O(n)、空间复杂度为 O(1) 的算法解决此问题。</li>
32+
<li><code>n == nums.length</code></li>
33+
<li><code>1 &lt;= n &lt;= 5 * 10<sup>4</sup></code></li>
34+
<li><code>-10<sup>9</sup> &lt;= nums[i] &lt;= 10<sup>9</sup></code></li>
3435
</ul>
3536

37+
<p>&nbsp;</p>
38+
39+
<p><strong>进阶:</strong>尝试设计时间复杂度为 O(n)、空间复杂度为 O(1) 的算法解决此问题。</p>
40+
3641
## 解法
3742

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

solution/0100-0199/0174.Dungeon Game/README.md

-3
Original file line numberDiff line numberDiff line change
@@ -88,12 +88,9 @@ table.dungeon, .dungeon th, .dungeon td {
8888

8989
<ul>
9090
<li>
91-
9291
<p>骑士的健康点数没有上限。</p>
93-
9492
</li>
9593
<li>任何房间都可能对骑士的健康点数造成威胁,也可能增加骑士的健康点数,包括骑士进入的左上角房间以及公主被监禁的右下角房间。</li>
96-
9794
</ul>
9895

9996
## 解法

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

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
| num | varchar |
1515
+-------------+---------+
1616
id is the primary key for this table.
17+
id is an autoincrement column.
1718
</pre>
1819

1920
<p>&nbsp;</p>

solution/0100-0199/0192.Word Frequency/README_EN.md

+5
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,11 @@
99
<p>For simplicity sake, you may assume:</p>
1010

1111
<ul>
12+
1213
<li><code>words.txt</code> contains only lowercase characters and space <code>&#39; &#39;</code> characters.</li>
14+
1315
<li>Each word must consist of lowercase characters only.</li>
16+
1417
<li>Words are separated by one or more whitespace characters.</li>
1518

1619
</ul>
@@ -44,7 +47,9 @@ day 1
4447
<p><b>Note:</b></p>
4548

4649
<ul>
50+
4751
<li>Don&#39;t worry about handling ties, it is guaranteed that each word&#39;s frequency count is unique.</li>
52+
4853
<li>Could you write it in one-line using <a href="http://tldp.org/HOWTO/Bash-Prog-Intro-HOWTO-4.html">Unix pipes</a>?</li>
4954

5055
</ul>

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

+4-2
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,16 @@ id是该表的主键列。
2121

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

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

26-
<p>以 <strong>任意顺序</strong> 返回结果表。</p>
26+
<p>以 <strong>任意顺序</strong> 返回结果表。 (<strong>注意</strong>: 仅需要写删除语句,将自动对剩余结果进行查询)</p>
2727

2828
<p>查询结果格式如下所示。</p>
2929

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

32+
<p>&nbsp;</p>
33+
3234
<p><strong>示例 1:</strong></p>
3335

3436
<pre>

solution/0200-0299/0207.Course Schedule/README_EN.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ To take course 1 you should have finished course 0, and to take course 0 you sho
3535
<p><strong>Constraints:</strong></p>
3636

3737
<ul>
38-
<li><code>1 &lt;= numCourses &lt;= 10<sup>5</sup></code></li>
38+
<li><code>1 &lt;= numCourses &lt;= 2000</code></li>
3939
<li><code>0 &lt;= prerequisites.length &lt;= 5000</code></li>
4040
<li><code>prerequisites[i].length == 2</code></li>
4141
<li><code>0 &lt;= a<sub>i</sub>, b<sub>i</sub> &lt; numCourses</code></li>

solution/0300-0399/0302.Smallest Rectangle Enclosing Black Pixels/README_EN.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@
3535
<li><code>n == image[i].length</code></li>
3636
<li><code>1 &lt;= m, n &lt;= 100</code></li>
3737
<li><code>image[i][j]</code> is either <code>&#39;0&#39;</code> or <code>&#39;1&#39;</code>.</li>
38-
<li><code>1 &lt;= x &lt; m</code></li>
39-
<li><code>1 &lt;= y &lt; n</code></li>
38+
<li><code>0 &lt;= x &lt; m</code></li>
39+
<li><code>0 &lt;= y &lt; n</code></li>
4040
<li><code>image[x][y] == &#39;1&#39;.</code></li>
4141
<li>The black pixels in the <code>image</code> only form <strong>one component</strong>.</li>
4242
</ul>

solution/0300-0399/0320.Generalized Abbreviation/README.md

-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
<li><meta charset="UTF-8" /><code>"22de"</code>&nbsp;(<code>"ab"</code> 变为&nbsp;<code>"2"</code>&nbsp;,&nbsp;<code>"bc"</code>&nbsp;变为&nbsp;<code>"2"</code>) &nbsp;是无效的,因为被选择的字符串是重叠的</li>
2424
</ul>
2525
</li>
26-
2726
</ul>
2827

2928
<p>给你一个字符串&nbsp;<code>word</code> ,返回&nbsp;<em>一个由</em>&nbsp;<code>word</code> 的<em>所有可能 <strong>广义缩写词</strong> 组成的列表</em>&nbsp;。按 <strong>任意顺序</strong> 返回答案。</p>

0 commit comments

Comments
 (0)