Skip to content

Commit d8eb5b4

Browse files
committed
feat: update lc problems
1 parent 5eef5e9 commit d8eb5b4

File tree

24 files changed

+164
-134
lines changed

24 files changed

+164
-134
lines changed

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

+10-15
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,30 @@
1-
# [28. 实现 strStr()](https://leetcode.cn/problems/find-the-index-of-the-first-occurrence-in-a-string)
1+
# [28. 找出字符串中第一个匹配项的下标](https://leetcode.cn/problems/find-the-index-of-the-first-occurrence-in-a-string)
22

33
[English Version](/solution/0000-0099/0028.Find%20the%20Index%20of%20the%20First%20Occurrence%20in%20a%20String/README_EN.md)
44

55
## 题目描述
66

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

9-
<p>实现&nbsp;<a href="https://baike.baidu.com/item/strstr/811469" target="_blank">strStr()</a>&nbsp;函数。</p>
10-
11-
<p>给你两个字符串&nbsp;<code>haystack</code> 和 <code>needle</code> ,请你在 <code>haystack</code> 字符串中找出 <code>needle</code> 字符串出现的第一个位置(下标从 0 开始)。如果不存在,则返回&nbsp; <code>-1</code><strong> </strong>。</p>
12-
13-
<p><strong>说明:</strong></p>
14-
15-
<p>当&nbsp;<code>needle</code>&nbsp;是空字符串时,我们应当返回什么值呢?这是一个在面试中很好的问题。</p>
16-
17-
<p>对于本题而言,当&nbsp;<code>needle</code>&nbsp;是空字符串时我们应当返回 0 。这与 C 语言的&nbsp;<a href="https://baike.baidu.com/item/strstr/811469" target="_blank">strstr()</a>&nbsp;以及 Java 的&nbsp;<a href="https://docs.oracle.com/javase/7/docs/api/java/lang/String.html#indexOf(java.lang.String)" target="_blank">indexOf()</a>&nbsp;定义相符。</p>
9+
<p>给你两个字符串&nbsp;<code>haystack</code> 和 <code>needle</code> ,请你在 <code>haystack</code> 字符串中找出 <code>needle</code> 字符串的第一个匹配项的下标(下标从 0 开始)。如果&nbsp;<code>needle</code> 不是 <code>haystack</code> 的一部分,则返回&nbsp; <code>-1</code><strong> </strong>。</p>
1810

1911
<p>&nbsp;</p>
2012

21-
<p><strong>示例 1:</strong></p>
13+
<p><strong class="example">示例 1:</strong></p>
2214

2315
<pre>
24-
<strong>输入:</strong>haystack = "hello", needle = "ll"
25-
<strong>输出:</strong>2
16+
<strong>输入:</strong>haystack = "sadbutsad", needle = "sad"
17+
<strong>输出:</strong>0
18+
<strong>解释:</strong>"sad" 在下标 0 和 6 处匹配。
19+
第一个匹配项的下标是 0 ,所以返回 0 。
2620
</pre>
2721

28-
<p><strong>示例 2:</strong></p>
22+
<p><strong class="example">示例 2:</strong></p>
2923

3024
<pre>
31-
<strong>输入:</strong>haystack = "aaaaa", needle = "bba"
25+
<strong>输入:</strong>haystack = "leetcode", needle = "leeto"
3226
<strong>输出:</strong>-1
27+
<strong>解释:</strong>"leeto" 没有在 "leetcode" 中出现,所以返回 -1 。
3328
</pre>
3429

3530
<p>&nbsp;</p>

solution/0000-0099/0039.Combination Sum/README_EN.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
<p>The <strong>same</strong> number may be chosen from <code>candidates</code> an <strong>unlimited number of times</strong>. Two combinations are unique if the frequency of at least one of the chosen numbers is different.</p>
1010

11-
<p>It is <strong>guaranteed</strong> that the number of unique combinations that sum up to <code>target</code> is less than <code>150</code> combinations for the given input.</p>
11+
<p>The test cases are generated such that the number of unique combinations that sum up to <code>target</code> is less than <code>150</code> combinations for the given input.</p>
1212

1313
<p>&nbsp;</p>
1414
<p><strong>Example 1:</strong></p>
@@ -41,7 +41,7 @@ These are the only two combinations.
4141

4242
<ul>
4343
<li><code>1 &lt;= candidates.length &lt;= 30</code></li>
44-
<li><code>1 &lt;= candidates[i] &lt;= 200</code></li>
44+
<li><code>2 &lt;= candidates[i] &lt;= 40</code></li>
4545
<li>All elements of <code>candidates</code> are <strong>distinct</strong>.</li>
4646
<li><code>1 &lt;= target &lt;= 500</code></li>
4747
</ul>

solution/0000-0099/0067.Add Binary/README.md

+12-12
Original file line numberDiff line numberDiff line change
@@ -6,30 +6,30 @@
66

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

9-
<p>给你两个二进制字符串,返回它们的和(用二进制表示)。</p>
10-
11-
<p>输入为 <strong>非空 </strong>字符串且只包含数字&nbsp;<code>1</code>&nbsp;&nbsp;<code>0</code>。</p>
9+
<p>给你两个二进制字符串 <code>a</code> 和 <code>b</code> ,以二进制字符串的形式返回它们的和。</p>
1210

1311
<p>&nbsp;</p>
1412

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

17-
<pre><strong>输入:</strong> a = &quot;11&quot;, b = &quot;1&quot;
18-
<strong>输出:</strong> &quot;100&quot;</pre>
15+
<pre>
16+
<strong>输入:</strong>a = "11", b = "1"
17+
<strong>输出:</strong>"100"</pre>
1918

20-
<p><strong>示例&nbsp;2:</strong></p>
19+
<p><strong>示例&nbsp;2</strong></p>
2120

22-
<pre><strong>输入:</strong> a = &quot;1010&quot;, b = &quot;1011&quot;
23-
<strong>输出:</strong> &quot;10101&quot;</pre>
21+
<pre>
22+
<strong>输入:</strong>a = "1010", b = "1011"
23+
<strong>输出:</strong>"10101"</pre>
2424

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

2727
<p><strong>提示:</strong></p>
2828

2929
<ul>
30-
<li>每个字符串仅由字符 <code>&#39;0&#39;</code> 或 <code>&#39;1&#39;</code> 组成。</li>
31-
<li><code>1 &lt;= a.length, b.length &lt;= 10^4</code></li>
32-
<li>字符串如果不是 <code>&quot;0&quot;</code> ,就都不含前导零。</li>
30+
<li><code>1 &lt;= a.length, b.length &lt;= 10<sup>4</sup></code></li>
31+
<li><code>a</code> 和 <code>b</code> 仅由字符 <code>'0'</code> 或 <code>'1'</code> 组成</li>
32+
<li>字符串如果不是 <code>"0"</code> ,就不含前导零</li>
3333
</ul>
3434

3535
## 解法

solution/0100-0199/0188.Best Time to Buy and Sell Stock IV/README_EN.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@
3131
<p><strong>Constraints:</strong></p>
3232

3333
<ul>
34-
<li><code>0 &lt;= k &lt;= 100</code></li>
35-
<li><code>0 &lt;= prices.length &lt;= 1000</code></li>
34+
<li><code>1 &lt;= k &lt;= 100</code></li>
35+
<li><code>1 &lt;= prices.length &lt;= 1000</code></li>
3636
<li><code>0 &lt;= prices[i] &lt;= 1000</code></li>
3737
</ul>
3838

solution/0300-0399/0336.Palindrome Pairs/README.md

+2
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
<strong>输出:</strong>[[0,1],[1,0]]
3333
</pre>
3434

35+
36+
3537
<p><strong>提示:</strong></p>
3638

3739
<ul>

solution/0400-0499/0457.Circular Array Loop/README_EN.md

+16-18
Original file line numberDiff line numberDiff line change
@@ -24,34 +24,32 @@
2424
<p>Return <code>true</code><em> if there is a <strong>cycle</strong> in </em><code>nums</code><em>, or </em><code>false</code><em> otherwise</em>.</p>
2525

2626
<p>&nbsp;</p>
27-
<p><strong>Example 1:</strong></p>
28-
27+
<p><strong class="example">Example 1:</strong></p>
28+
<img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/0400-0499/0457.Circular%20Array%20Loop/images/img1.jpg" style="width: 402px; height: 289px;" />
2929
<pre>
3030
<strong>Input:</strong> nums = [2,-1,1,2,2]
3131
<strong>Output:</strong> true
32-
<strong>Explanation:</strong>
33-
There is a cycle from index 0 -&gt; 2 -&gt; 3 -&gt; 0 -&gt; ...
34-
The cycle&#39;s length is 3.
32+
<strong>Explanation:</strong> The graph shows how the indices are connected. White nodes are jumping forward, while red is jumping backward.
33+
We can see the cycle 0 --&gt; 2 --&gt; 3 --&gt; 0 --&gt; ..., and all of its nodes are white (jumping in the same direction).
3534
</pre>
3635

37-
<p><strong>Example 2:</strong></p>
38-
36+
<p><strong class="example">Example 2:</strong></p>
37+
<img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/0400-0499/0457.Circular%20Array%20Loop/images/img2.jpg" style="width: 402px; height: 390px;" />
3938
<pre>
40-
<strong>Input:</strong> nums = [-1,2]
39+
<strong>Input:</strong> nums = [-1,-2,-3,-4,-5,6]
4140
<strong>Output:</strong> false
42-
<strong>Explanation:</strong>
43-
The sequence from index 1 -&gt; 1 -&gt; 1 -&gt; ... is not a cycle because the sequence&#39;s length is 1.
44-
By definition the sequence&#39;s length must be strictly greater than 1 to be a cycle.
41+
<strong>Explanation:</strong> The graph shows how the indices are connected. White nodes are jumping forward, while red is jumping backward.
42+
The only cycle is of size 1, so we return false.
4543
</pre>
4644

47-
<p><strong>Example 3:</strong></p>
48-
45+
<p><strong class="example">Example 3:</strong></p>
46+
<img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/0400-0499/0457.Circular%20Array%20Loop/images/img3.jpg" style="width: 497px; height: 242px;" />
4947
<pre>
50-
<strong>Input:</strong> nums = [-2,1,-1,-2,-2]
51-
<strong>Output:</strong> false
52-
<strong>Explanation:</strong>
53-
The sequence from index 1 -&gt; 2 -&gt; 1 -&gt; ... is not a cycle because nums[1] is positive, but nums[2] is negative.
54-
Every nums[seq[j]] must be either all positive or all negative.
48+
<strong>Input:</strong> nums = [1,-1,5,1,4]
49+
<strong>Output:</strong> true
50+
<strong>Explanation:</strong> The graph shows how the indices are connected. White nodes are jumping forward, while red is jumping backward.
51+
We can see the cycle 0 --&gt; 1 --&gt; 0 --&gt; ..., and while it is of size &gt; 1, it has a node jumping forward and a node jumping backward, so <strong>it is not a cycle</strong>.
52+
We can see the cycle 3 --&gt; 4 --&gt; 3 --&gt; ..., and all of its nodes are white (jumping in the same direction).
5553
</pre>
5654

5755
<p>&nbsp;</p>
Loading
Loading

solution/0500-0599/0502.IPO/Solution.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
class Solution:
2-
def findMaximizedCapital(self, k: int, w: int, profits: List[int], capital: List[int]) -> int:
2+
def findMaximizedCapital(
3+
self, k: int, w: int, profits: List[int], capital: List[int]
4+
) -> int:
35
h1 = [(c, p) for c, p in zip(capital, profits)]
46
heapify(h1)
57
h2 = []

solution/0500-0599/0554.Brick Wall/README.md

+2
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
<strong>输出:</strong>3
2929
</pre>
3030

31+
32+
3133
<p><strong>提示:</strong></p>
3234

3335
<ul>

solution/0600-0699/0652.Find Duplicate Subtrees/README.md

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

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

9-
<p>给定一棵二叉树 <code>root</code>,返回所有<strong>重复的子树</strong>。</p>
9+
<p>给你一棵二叉树的根节点 <code>root</code> ,返回所有 <strong>重复的子树 </strong>。</p>
1010

11-
<p>对于同一类的重复子树,你只需要返回其中任意<strong>一棵</strong>的根结点即可。</p>
11+
<p>对于同一类的重复子树,你只需要返回其中任意 <strong>一棵 </strong>的根结点即可。</p>
1212

13-
<p>如果两棵树具有<strong>相同的结构</strong><strong>相同的结点值</strong>,则它们是<strong>重复</strong>的。</p>
13+
<p>如果两棵树具有<strong> 相同的结构</strong><strong>相同的结点值 </strong>,则认为二者是 <strong>重复 </strong>的。</p>
1414

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

@@ -43,7 +43,7 @@
4343
<p><strong>提示:</strong></p>
4444

4545
<ul>
46-
<li>树中的结点数在<code>[1,10^4]</code>范围内。</li>
46+
<li>树中的结点数在 <code>[1, 5000]</code> 范围内。</li>
4747
<li><code>-200 &lt;= Node.val &lt;= 200</code></li>
4848
</ul>
4949

solution/0600-0699/0672.Bulb Switcher II/README.md

+46-21
Original file line numberDiff line numberDiff line change
@@ -6,39 +6,64 @@
66

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

9-
<p>现有一个房间,墙上挂有&nbsp;<code>n</code>&nbsp;只已经打开的灯泡和 4 个按钮。在进行了&nbsp;<code>m</code>&nbsp;次未知操作后,你需要返回这&nbsp;<code>n</code>&nbsp;只灯泡可能有多少种不同的状态。</p>
9+
<p>房间中有 <code>n</code>&nbsp;只已经打开的灯泡,编号从 <code>1</code><code>n</code> 。墙上挂着 <strong>4 个开关</strong> 。</p>
1010

11-
<p>假设这 <code>n</code> 只灯泡被编号为 [1, 2, 3 ..., n],这 4 个按钮的功能如下:</p>
11+
<p>这 4 个开关各自都具有不同的功能,其中:</p>
1212

13-
<ol>
14-
<li>将所有灯泡的状态反转(即开变为关,关变为开)</li>
15-
<li>将编号为偶数的灯泡的状态反转</li>
16-
<li>将编号为奇数的灯泡的状态反转</li>
17-
<li>将编号为 <code>3k+1</code> 的灯泡的状态反转(k = 0, 1, 2, ...)</li>
18-
</ol>
13+
<ul>
14+
<li><strong>开关 1 :</strong>反转当前所有灯的状态(即开变为关,关变为开)</li>
15+
<li><strong>开关 2 :</strong>反转编号为偶数的灯的状态(即 <code>2, 4, ...</code>)</li>
16+
<li><strong>开关 3 :</strong>反转编号为奇数的灯的状态(即 <code>1, 3, ...</code>)</li>
17+
<li><strong>开关 4 :</strong>反转编号为 <code>j = 3k + 1</code> 的灯的状态,其中 <code>k = 0, 1, 2, ...</code>(即 <code>1, 4, 7, 10, ...</code>)</li>
18+
</ul>
1919

20-
<p><strong>示例 1:</strong></p>
20+
<p>你必须 <strong>恰好</strong> 按压开关 <code>presses</code> 次。每次按压,你都需要从 4 个开关中选出一个来执行按压操作。</p>
2121

22-
<pre><strong>输入:</strong> n = 1, m = 1.
23-
<strong>输出:</strong> 2
24-
<strong>说明:</strong> 状态为: [开], [关]
22+
<p>给你两个整数 <code>n</code> 和 <code>presses</code> ,执行完所有按压之后,返回 <strong>不同可能状态</strong> 的数量。</p>
23+
24+
<p>&nbsp;</p>
25+
26+
<p><strong>示例 1:</strong></p>
27+
28+
<pre>
29+
<strong>输入:</strong>n = 1, presses = 1
30+
<strong>输出:</strong>2
31+
<strong>解释:</strong>状态可以是:
32+
- 按压开关 1 ,[关]
33+
- 按压开关 2 ,[开]
2534
</pre>
2635

27-
<p><strong>示例 2:</strong></p>
36+
<p><strong>示例 2</strong></p>
2837

29-
<pre><strong>输入:</strong> n = 2, m = 1.
30-
<strong>输出:</strong> 3
31-
<strong>说明:</strong> 状态为: [开, 关], [关, 开], [关, 关]
38+
<pre>
39+
<strong>输入:</strong>n = 2, presses = 1
40+
<strong>输出:</strong>3
41+
<strong>解释:</strong>状态可以是:
42+
- 按压开关 1 ,[关, 关]
43+
- 按压开关 2 ,[开, 关]
44+
- 按压开关 3 ,[关, 开]
3245
</pre>
3346

34-
<p><strong>示例 3:</strong></p>
47+
<p><strong>示例 3</strong></p>
3548

36-
<pre><strong>输入:</strong> n = 3, m = 1.
37-
<strong>输出:</strong> 4
38-
<strong>说明:</strong> 状态为: [关, 开, 关], [开, 关, 开], [关, 关, 关], [关, 开, 开].
49+
<pre>
50+
<strong>输入:</strong>n = 3, presses = 1
51+
<strong>输出:</strong>4
52+
<strong>解释:</strong>状态可以是:
53+
- 按压开关 1 ,[关, 关, 关]
54+
- 按压开关 2 ,[关, 开, 关]
55+
- 按压开关 3 ,[开, 关, 开]
56+
- 按压开关 4 ,[关, 开, 开]
3957
</pre>
4058

41-
<p><strong>注意:</strong>&nbsp;<code>n</code>&nbsp;&nbsp;<code>m</code> 都属于 [0, 1000].</p>
59+
<p>&nbsp;</p>
60+
61+
<p><strong>提示:</strong></p>
62+
63+
<ul>
64+
<li><code>1 &lt;= n &lt;= 1000</code></li>
65+
<li><code>0 &lt;= presses &lt;= 1000</code></li>
66+
</ul>
4267

4368
## 解法
4469

solution/0600-0699/0694.Number of Distinct Islands/README.md

+17-26
Original file line numberDiff line numberDiff line change
@@ -14,40 +14,31 @@
1414

1515
<p><strong>示例 1:</strong></p>
1616

17-
<pre>11000
18-
11000
19-
00011
20-
00011
21-
</pre>
22-
23-
<p>给定上图,返回结果 <code>1</code> 。</p>
24-
25-
<p><strong>示例 2:</strong></p>
26-
27-
<pre>11011
28-
10000
29-
00001
30-
11011</pre>
17+
<p><img src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/0600-0699/0694.Number%20of%20Distinct%20Islands/images/distinctisland1-1-grid.jpg" /></p>
3118

32-
<p>给定上图,返回结果 <code>3</code> 。<br>
33-
<br>
34-
<strong>注意:</strong></p>
35-
36-
<pre>11
37-
1
19+
<pre>
20+
<strong>输入:</strong> grid = [[1,1,0,0,0],[1,1,0,0,0],[0,0,0,1,1],[0,0,0,1,1]]
21+
<b>输出:</b>1
3822
</pre>
3923

40-
<p></p>
24+
<p><strong>示例 2:</strong></p>
4125

42-
<pre> 1
43-
11
44-
</pre>
26+
<pre>
27+
<strong>输入:</strong> grid = [[1,1,0,1,1],[1,0,0,0,0],[0,0,0,0,1],[1,1,0,1,1]]
28+
<b>输出</b><strong>:</strong> 3</pre>
4529

46-
<p>是不同的岛屿,因为我们不考虑旋转、翻转操作。</p>
30+
<p><img src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/0600-0699/0694.Number%20of%20Distinct%20Islands/images/distinctisland1-2-grid.jpg" /></p>
4731

4832
<p>&nbsp;</p>
4933

50-
<p><strong>提示:</strong>二维数组每维的大小都不会超过 50 。</p>
34+
<p><strong>提示:</strong></p>
35+
36+
<ul>
37+
<li><code>m == grid.length</code></li>
38+
<li><code>n == grid[i].length</code></li>
39+
<li><code>1 &lt;= m, n &lt;= 50</code></li>
40+
<li><code>grid[i][j]</code>&nbsp;仅包含&nbsp;<code>0</code>&nbsp;或&nbsp;<code>1</code></li>
41+
</ul>
5142

5243
## 解法
5344

solution/0700-0799/0708.Insert into a Sorted Circular 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 a Circular Linked List node, which is sorted in ascending order, write a function to insert a value <code>insertVal</code> into the list such that it remains a sorted circular list. The given node can be a reference to any single node in the list and may not necessarily be the smallest value in the circular list.</p>
7+
<p>Given a Circular Linked List node, which is sorted in non-descending order, write a function to insert a value <code>insertVal</code> into the list such that it remains a sorted circular list. The given node can be a reference to any single node in the list and may not necessarily be the smallest value in the circular list.</p>
88

99
<p>If there are multiple suitable places for insertion, you may choose any place to insert the new value. After the insertion, the circular list should remain sorted.</p>
1010

solution/0700-0799/0775.Global and Local Inversions/README.md

+2
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@
4242
<strong>解释:</strong>有 2 个全局倒置,和 1 个局部倒置。
4343
</pre>
4444

45+
46+
4547
<p><strong>提示:</strong></p>
4648

4749
<ul>

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>

0 commit comments

Comments
 (0)