Skip to content

Commit e6906e4

Browse files
committed
feat: update lc problems
1 parent b81370b commit e6906e4

File tree

17 files changed

+78
-56
lines changed

17 files changed

+78
-56
lines changed

solution/0000-0099/0028.Find the Index of the First Occurrence in a String/README.md

-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141
<li><code>haystack</code> 和 <code>needle</code> 仅由小写英文字符组成</li>
4242
</ul>
4343

44-
4544
## 解法
4645

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

solution/0000-0099/0028.Find the Index of the First Occurrence in a String/README_EN.md

-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ The first occurrence is at index 0, so we return 0.
3232
<li><code>haystack</code> and <code>needle</code> consist of only lowercase English characters.</li>
3333
</ul>
3434

35-
3635
## Solutions
3736

3837
<!-- tabs:start -->

solution/0000-0099/0048.Rotate Image/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ func rotate(matrix [][]int) {
202202
matrix[i][j], matrix[j][i] = matrix[j][i], matrix[i][j]
203203
}
204204
}
205-
205+
206206
for i := 0; i < n; i++ {
207207
for j, k := 0, n-1; j < k; j, k = j+1, k-1 {
208208
matrix[i][j], matrix[i][k] = matrix[i][k], matrix[i][j]

solution/0100-0199/0125.Valid Palindrome/README.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,26 @@
66

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

9-
<p>如果在将所有大写字符转换为小写字符、并移除所有非字母数字字符之后,短语正着读和反着读都一样。则可以认为该短语是一个回文串。</p>
9+
<p>如果在将所有大写字符转换为小写字符、并移除所有非字母数字字符之后,短语正着读和反着读都一样。则可以认为该短语是一个 <strong>回文串</strong> 。</p>
1010

1111
<p>字母和数字都属于字母数字字符。</p>
1212

13-
<p>给你一个字符串 <code>s</code>,如果它是回文串,返回 <code>true</code><em> </em>;否则,返回<em> </em><code>false</code><em> </em>。</p>
13+
<p>给你一个字符串 <code>s</code>,如果它是 <strong>回文串</strong> ,返回 <code>true</code><em> </em>;否则,返回<em> </em><code>false</code><em> </em>。</p>
1414

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

1717
<p><strong>示例 1:</strong></p>
1818

1919
<pre>
20-
<strong>输入:</strong> "A man, a plan, a canal: Panama"
20+
<strong>输入:</strong> s = "A man, a plan, a canal: Panama"
2121
<strong>输出:</strong>true
2222
<strong>解释:</strong>"amanaplanacanalpanama" 是回文串。
2323
</pre>
2424

2525
<p><strong>示例 2:</strong></p>
2626

2727
<pre>
28-
<strong>输入:</strong>"race a car"
28+
<strong>输入:</strong>s = "race a car"
2929
<strong>输出:</strong>false
3030
<strong>解释:</strong>"raceacar" 不是回文串。
3131
</pre>

solution/0100-0199/0137.Single Number II/README.md

+7-9
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@
66

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

9-
<p>给你一个整数数组 <code>nums</code> ,除某个元素仅出现 <strong>一次</strong> 外,其余每个元素都恰出现 <strong>三次 。</strong>请你找出并返回那个只出现了一次的元素。</p>
9+
<p>给你一个整数数组&nbsp;<code>nums</code> ,除某个元素仅出现 <strong>一次</strong> 外,其余每个元素都恰出现 <strong>三次 。</strong>请你找出并返回那个只出现了一次的元素。</p>
1010

11-
<p> </p>
11+
<p>你必须设计并实现线性时间复杂度的算法且不使用额外空间来解决此问题。</p>
12+
13+
<p>&nbsp;</p>
1214

1315
<p><strong>示例 1:</strong></p>
1416

@@ -24,20 +26,16 @@
2426
<strong>输出:</strong>99
2527
</pre>
2628

27-
<p> </p>
29+
<p>&nbsp;</p>
2830

2931
<p><strong>提示:</strong></p>
3032

3133
<ul>
32-
<li><code>1 <= nums.length <= 3 * 10<sup>4</sup></code></li>
33-
<li><code>-2<sup>31</sup> <= nums[i] <= 2<sup>31</sup> - 1</code></li>
34+
<li><code>1 &lt;= nums.length &lt;= 3 * 10<sup>4</sup></code></li>
35+
<li><code>-2<sup>31</sup> &lt;= nums[i] &lt;= 2<sup>31</sup> - 1</code></li>
3436
<li><code>nums</code> 中,除某个元素仅出现 <strong>一次</strong> 外,其余每个元素都恰出现 <strong>三次</strong></li>
3537
</ul>
3638

37-
<p> </p>
38-
39-
<p><strong>进阶:</strong>你的算法应该具有线性时间复杂度。 你可以不使用额外空间来实现吗?</p>
40-
4139
## 解法
4240

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

solution/0200-0299/0260.Single Number III/README.md

+7-7
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,11 @@
66

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

9-
<p>给定一个整数数组 <code>nums</code>,其中恰好有两个元素只出现一次,其余所有元素均出现两次。 找出只出现一次的那两个元素。你可以按 <strong>任意顺序</strong> 返回答案。</p>
9+
<p>给你一个整数数组&nbsp;<code>nums</code>,其中恰好有两个元素只出现一次,其余所有元素均出现两次。 找出只出现一次的那两个元素。你可以按 <strong>任意顺序</strong> 返回答案。</p>
1010

11-
<p> </p>
11+
<p>你必须设计并实现线性时间复杂度的算法且仅使用常量额外空间来解决此问题。</p>
1212

13-
<p><strong>进阶:</strong>你的算法应该具有线性时间复杂度。你能否仅使用常数空间复杂度来实现?</p>
14-
15-
<p> </p>
13+
<p>&nbsp;</p>
1614

1715
<p><strong>示例 1:</strong></p>
1816

@@ -36,11 +34,13 @@
3634
<strong>输出:</strong>[1,0]
3735
</pre>
3836

37+
<p>&nbsp;</p>
38+
3939
<p><strong>提示:</strong></p>
4040

4141
<ul>
42-
<li><code>2 <= nums.length <= 3 * 10<sup>4</sup></code></li>
43-
<li><code>-2<sup>31</sup> <= nums[i] <= 2<sup>31</sup> - 1</code></li>
42+
<li><code>2 &lt;= nums.length &lt;= 3 * 10<sup>4</sup></code></li>
43+
<li><code>-2<sup>31</sup> &lt;= nums[i] &lt;= 2<sup>31</sup> - 1</code></li>
4444
<li>除两个只出现一次的整数外,<code>nums</code> 中的其他数字都出现两次</li>
4545
</ul>
4646

solution/0200-0299/0298.Binary Tree Longest Consecutive Sequence/README_EN.md

+6-4
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,23 @@
44

55
## Description
66

7-
<p>Given the <code>root</code> of a binary tree, return <em>the length of the longest consecutive sequence path</em>.</p>
7+
<p>Given the <code>root</code> of a binary tree, return <em>the length of the longest <strong>consecutive sequence path</strong></em>.</p>
88

9-
<p>The path refers to any sequence of nodes from some starting node to any node in the tree along the parent-child connections. The longest consecutive path needs to be from parent to child (cannot be the reverse).</p>
9+
<p>A <strong>consecutive sequence path</strong> is a path where the values <strong>increase by one</strong> along the path.</p>
10+
11+
<p>Note that the path can start <strong>at any node</strong> in the tree, and you cannot go from a node to its parent in the path.</p>
1012

1113
<p>&nbsp;</p>
1214
<p><strong>Example 1:</strong></p>
13-
<img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/0200-0299/0298.Binary%20Tree%20Longest%20Consecutive%20Sequence/images/consec1-1-tree.jpg" style="width: 322px; height: 421px;" />
15+
<img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/0200-0299/0298.Binary%20Tree%20Longest%20Consecutive%20Sequence/images/consec1-1-tree.jpg" style="width: 306px; height: 400px;" />
1416
<pre>
1517
<strong>Input:</strong> root = [1,null,3,2,4,null,null,null,5]
1618
<strong>Output:</strong> 3
1719
<strong>Explanation:</strong> Longest consecutive sequence path is 3-4-5, so return 3.
1820
</pre>
1921

2022
<p><strong>Example 2:</strong></p>
21-
<img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/0200-0299/0298.Binary%20Tree%20Longest%20Consecutive%20Sequence/images/consec1-2-tree.jpg" style="width: 262px; height: 421px;" />
23+
<img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/0200-0299/0298.Binary%20Tree%20Longest%20Consecutive%20Sequence/images/consec1-2-tree.jpg" style="width: 249px; height: 400px;" />
2224
<pre>
2325
<strong>Input:</strong> root = [2,null,3,2,null,1]
2426
<strong>Output:</strong> 2

solution/0300-0399/0363.Max Sum of Rectangle No Larger Than K/README_EN.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
<ul>
3131
<li><code>m == matrix.length</code></li>
3232
<li><code>n == matrix[i].length</code></li>
33-
<li><code>1 &lt;= m, n &lt;= 100</code></li>
33+
<li><code>1 &lt;= m, n &lt;= 200</code></li>
3434
<li><code>-100 &lt;= matrix[i][j] &lt;= 100</code></li>
3535
<li><code>-10<sup>5</sup> &lt;= k &lt;= 10<sup>5</sup></code></li>
3636
</ul>

solution/0700-0799/0749.Contain Virus/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,14 @@
2525
<strong>输出:</strong> 10
2626
<strong>解释:</strong>一共有两块被病毒感染的区域。
2727
在第一天,添加 5 墙隔离病毒区域的左侧。病毒传播后的状态是:
28-
<img src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/0700-0799/0749.Contain%20Virus/images/virus12edited-grid.jpg" />
28+
<img src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/0700-0799/0749.Contain%20Virus/images/virus12edited-grid.jpg" style="height: 261px; width: 500px;" />
2929
第二天,在右侧添加 5 个墙来隔离病毒区域。此时病毒已经被完全控制住了。
3030
<img src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/0700-0799/0749.Contain%20Virus/images/virus13edited-grid.jpg" style="height: 261px; width: 500px;" />
3131
</pre>
3232

3333
<p><strong>示例 2:</strong></p>
3434

35-
<p><img src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/0700-0799/0749.Contain%20Virus/images/virus2-grid.jpg" style="height: 253px; width: https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/0700-0799/0749.Contain%20Virus/images/653px;" /></p>
35+
<p><img src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/0700-0799/0749.Contain%20Virus/images/virus2-grid.jpg" style="height: 253px; width: 653px;" /></p>
3636

3737
<pre>
3838
<strong>输入:</strong> isInfected = [[1,1,1],[1,0,1],[1,1,1]]

solution/0700-0799/0757.Set Intersection Size At Least Two/README_EN.md

+24-9
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,42 @@
44

55
## Description
66

7-
<p>An integer interval <code>[a, b]</code> (for integers <code>a &lt; b</code>) is a set of all consecutive integers from <code>a</code> to <code>b</code>, including <code>a</code> and <code>b</code>.</p>
7+
<p>You are given a 2D integer array <code>intervals</code> where <code>intervals[i] = [start<sub>i</sub>, end<sub>i</sub>]</code> represents all the integers from <code>start<sub>i</sub></code> to <code>end<sub>i</sub></code> inclusively.</p>
88

9-
<p>Find the minimum size of a set S such that for every integer interval A in <code>intervals</code>, the intersection of S with A has a size of at least two.</p>
9+
<p>A <strong>containing set</strong> is an array <code>nums</code> where each interval from <code>intervals</code> has <strong>at least two</strong> integers in <code>nums</code>.</p>
10+
11+
<ul>
12+
<li>For example, if <code>intervals = [[1,3], [3,7], [8,9]]</code>, then <code>[1,2,4,7,8,9]</code> and <code>[2,3,4,8,9]</code> are <strong>containing sets</strong>.</li>
13+
</ul>
14+
15+
<p>Return <em>the minimum possible size of a containing set</em>.</p>
1016

1117
<p>&nbsp;</p>
12-
<p><strong>Example 1:</strong></p>
18+
<p><strong class="example">Example 1:</strong></p>
19+
20+
<pre>
21+
<strong>Input:</strong> intervals = [[1,3],[3,7],[8,9]]
22+
<strong>Output:</strong> 5
23+
<strong>Explanation:</strong> let nums = [2, 3, 4, 8, 9].
24+
It can be shown that there cannot be any containing array of size 4.
25+
</pre>
26+
27+
<p><strong class="example">Example 2:</strong></p>
1328

1429
<pre>
1530
<strong>Input:</strong> intervals = [[1,3],[1,4],[2,5],[3,5]]
1631
<strong>Output:</strong> 3
17-
<strong>Explanation:</strong> Consider the set S = {2, 3, 4}. For each interval, there are at least 2 elements from S in the interval.
18-
Also, there isn&#39;t a smaller size set that fulfills the above condition.
19-
Thus, we output the size of this set, which is 3.
32+
<strong>Explanation:</strong> let nums = [2, 3, 4].
33+
It can be shown that there cannot be any containing array of size 2.
2034
</pre>
2135

22-
<p><strong>Example 2:</strong></p>
36+
<p><strong class="example">Example 3:</strong></p>
2337

2438
<pre>
2539
<strong>Input:</strong> intervals = [[1,2],[2,3],[2,4],[4,5]]
2640
<strong>Output:</strong> 5
27-
<strong>Explanation:</strong> An example of a minimum sized set is {1, 2, 3, 4, 5}.
41+
<strong>Explanation:</strong> let nums = [1, 2, 3, 4, 5].
42+
It can be shown that there cannot be any containing array of size 4.
2843
</pre>
2944

3045
<p>&nbsp;</p>
@@ -33,7 +48,7 @@ Thus, we output the size of this set, which is 3.
3348
<ul>
3449
<li><code>1 &lt;= intervals.length &lt;= 3000</code></li>
3550
<li><code>intervals[i].length == 2</code></li>
36-
<li><code>0 &lt;= a<sub>i</sub> &lt;&nbsp;b<sub>i</sub> &lt;= 10<sup>8</sup></code></li>
51+
<li><code>0 &lt;= start<sub>i</sub> &lt; end<sub>i</sub> &lt;= 10<sup>8</sup></code></li>
3752
</ul>
3853

3954
## Solutions

solution/0800-0899/0830.Positions of Large Groups/README.md

+2
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@
4848
<strong>输出:</strong>[]
4949
</pre>
5050

51+
52+
5153
<p><strong>提示:</strong></p>
5254

5355
<ul>

solution/0900-0999/0934.Shortest Bridge/README.md

+20-11
Original file line numberDiff line numberDiff line change
@@ -6,41 +6,50 @@
66

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

9-
<p>在给定的二维二进制数组 <code>A</code> 中,存在两座岛。(岛是由四面相连的 <code>1</code> 形成的一个最大组。)</p>
9+
<p>给你一个大小为 <code>n x n</code> 的二元矩阵 <code>grid</code> ,其中 <code>1</code> 表示陆地,<code>0</code> 表示水域。</p>
1010

11-
<p>现在,我们可以将 <code>0</code> 变为 <code>1</code>,以使两座岛连接起来,变成一座岛。</p>
11+
<p><strong>岛</strong> 是由四面相连的 <code>1</code> 形成的一个最大组,即不会与非组内的任何其他 <code>1</code> 相连。<code>grid</code> 中 <strong>恰好存在两座岛</strong> 。</p>
1212

13-
<p>返回必须翻转的 <code>0</code> 的最小数目。(可以保证答案至少是 <code>1</code> 。)</p>
13+
<div class="original__bRMd">
14+
<div>
15+
<p>你可以将任意数量的 <code>0</code> 变为 <code>1</code> ,以使两座岛连接起来,变成 <strong>一座岛</strong> 。</p>
1416

15-
<p> </p>
17+
<p>返回必须翻转的 <code>0</code> 的最小数目。</p>
18+
</div>
19+
</div>
20+
21+
<p>&nbsp;</p>
1622

1723
<p><strong>示例 1:</strong></p>
1824

1925
<pre>
20-
<strong>输入:</strong>A = [[0,1],[1,0]]
26+
<strong>输入:</strong>grid = [[0,1],[1,0]]
2127
<strong>输出:</strong>1
2228
</pre>
2329

2430
<p><strong>示例 2:</strong></p>
2531

2632
<pre>
27-
<strong>输入:</strong>A = [[0,1,0],[0,0,0],[0,0,1]]
33+
<strong>输入:</strong>grid = [[0,1,0],[0,0,0],[0,0,1]]
2834
<strong>输出:</strong>2
2935
</pre>
3036

3137
<p><strong>示例 3:</strong></p>
3238

3339
<pre>
34-
<strong>输入:</strong>A = [[1,1,1,1,1],[1,0,0,0,1],[1,0,1,0,1],[1,0,0,0,1],[1,1,1,1,1]]
35-
<strong>输出:</strong>1</pre>
40+
<strong>输入:</strong>grid = [[1,1,1,1,1],[1,0,0,0,1],[1,0,1,0,1],[1,0,0,0,1],[1,1,1,1,1]]
41+
<strong>输出:</strong>1
42+
</pre>
3643

37-
<p> </p>
44+
<p>&nbsp;</p>
3845

3946
<p><strong>提示:</strong></p>
4047

4148
<ul>
42-
<li><code>2 <= A.length == A[0].length <= 100</code></li>
43-
<li><code>A[i][j] == 0</code> 或 <code>A[i][j] == 1</code></li>
49+
<li><code>n == grid.length == grid[i].length</code></li>
50+
<li><code>2 &lt;= n &lt;= 100</code></li>
51+
<li><code>grid[i][j]</code> 为 <code>0</code> 或 <code>1</code></li>
52+
<li><code>grid</code> 中恰有两个岛</li>
4453
</ul>
4554

4655
## 解法

solution/0900-0999/0983.Minimum Cost For Tickets/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ class Solution:
8989
j = bisect_left(days, days[i] + d)
9090
res = min(res, c + dfs(j))
9191
return res
92-
92+
9393
return dfs(0)
9494
```
9595

solution/0900-0999/0983.Minimum Cost For Tickets/README_EN.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ class Solution:
7575
j = bisect_left(days, days[i] + d)
7676
res = min(res, c + dfs(j))
7777
return res
78-
78+
7979
return dfs(0)
8080
```
8181

solution/1000-1099/1032.Stream of Characters/README_EN.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ class StreamChecker {
146146
trie.insert(w);
147147
}
148148
}
149-
149+
150150
public boolean query(char letter) {
151151
sb.append(letter);
152152
return trie.query(sb);
@@ -204,7 +204,7 @@ public:
204204
trie->insert(w);
205205
}
206206
}
207-
207+
208208
bool query(char letter) {
209209
s += letter;
210210
return trie->search(s);

solution/2300-2399/2394.Employees With Deductions/README.md

-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@ Employee 3:
9595
- Employee 3 did not work their hours and will be deducted.
9696
</pre>
9797

98-
9998
## 解法
10099

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

solution/2300-2399/2394.Employees With Deductions/README_EN.md

-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@ Employee 3:
9393
- Employee 3 did not work their hours and will be deducted.
9494
</pre>
9595

96-
9796
## Solutions
9897

9998
<!-- tabs:start -->

0 commit comments

Comments
 (0)