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

Lines changed: 10 additions & 15 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 12 additions & 12 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 2 additions & 0 deletions
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

Lines changed: 16 additions & 18 deletions
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>
15.6 KB
Loading
20.5 KB
Loading

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

Lines changed: 3 additions & 1 deletion
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

Lines changed: 2 additions & 0 deletions
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>

0 commit comments

Comments
 (0)