Skip to content

Commit 7849c5b

Browse files
authored
feat: add weekly contest 437 & biweekly contest 150 (doocs#4069)
1 parent d467151 commit 7849c5b

File tree

86 files changed

+2385
-213
lines changed

Some content is hidden

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

86 files changed

+2385
-213
lines changed

solution/0000-0099/0003.Longest Substring Without Repeating Characters/README_EN.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ tags:
1818

1919
<!-- description:start -->
2020

21-
<p>Given a string <code>s</code>, find the length of the <strong>longest</strong> <span data-keyword="substring-nonempty"><strong>substring</strong></span> without repeating characters.</p>
21+
<p>Given a string <code>s</code>, find the length of the <strong>longest</strong> <span data-keyword="substring-nonempty"><strong>substring</strong></span> without duplicate characters.</p>
2222

2323
<p>&nbsp;</p>
2424
<p><strong class="example">Example 1:</strong></p>

solution/0700-0799/0763.Partition Labels/README_EN.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ tags:
1919

2020
<!-- description:start -->
2121

22-
<p>You are given a string <code>s</code>. We want to partition the string into as many parts as possible so that each letter appears in at most one part.</p>
22+
<p>You are given a string <code>s</code>. We want to partition the string into as many parts as possible so that each letter appears in at most one part. For example, the string <code>&quot;ababcc&quot;</code> can be partitioned into <code>[&quot;abab&quot;, &quot;cc&quot;]</code>, but partitions such as <code>[&quot;aba&quot;, &quot;bcc&quot;]</code> or <code>[&quot;ab&quot;, &quot;ab&quot;, &quot;cc&quot;]</code> are invalid.</p>
2323

2424
<p>Note that the partition is done so that after concatenating all the parts in order, the resultant string should be <code>s</code>.</p>
2525

solution/0900-0999/0980.Unique Paths III/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ tags:
4646

4747
<pre><strong>输入:</strong>[[1,0,0,0],[0,0,0,0],[0,0,0,2]]
4848
<strong>输出:</strong>4
49-
<strong>解释:</strong>我们有以下四条路径:
49+
<strong>解释:</strong>我们有以下四条路径:
5050
1. (0,0),(0,1),(0,2),(0,3),(1,3),(1,2),(1,1),(1,0),(2,0),(2,1),(2,2),(2,3)
5151
2. (0,0),(0,1),(1,1),(1,0),(2,0),(2,1),(2,2),(1,2),(0,2),(0,3),(1,3),(2,3)
5252
3. (0,0),(1,0),(2,0),(2,1),(2,2),(1,2),(1,1),(0,1),(0,2),(0,3),(1,3),(2,3)

solution/0900-0999/0980.Unique Paths III/README_EN.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ tags:
3636
<pre>
3737
<strong>Input:</strong> grid = [[1,0,0,0],[0,0,0,0],[0,0,2,-1]]
3838
<strong>Output:</strong> 2
39-
<strong>Explanation:</strong> We have the following two paths:
39+
<strong>Explanation:</strong> We have the following two paths:
4040
1. (0,0),(0,1),(0,2),(0,3),(1,3),(1,2),(1,1),(1,0),(2,0),(2,1),(2,2)
4141
2. (0,0),(1,0),(2,0),(2,1),(1,1),(0,1),(0,2),(0,3),(1,3),(1,2),(2,2)
4242
</pre>
@@ -46,7 +46,7 @@ tags:
4646
<pre>
4747
<strong>Input:</strong> grid = [[1,0,0,0],[0,0,0,0],[0,0,0,2]]
4848
<strong>Output:</strong> 4
49-
<strong>Explanation:</strong> We have the following four paths:
49+
<strong>Explanation:</strong> We have the following four paths:
5050
1. (0,0),(0,1),(0,2),(0,3),(1,3),(1,2),(1,1),(1,0),(2,0),(2,1),(2,2),(2,3)
5151
2. (0,0),(0,1),(1,1),(1,0),(2,0),(2,1),(2,2),(1,2),(0,2),(0,3),(1,3),(2,3)
5252
3. (0,0),(1,0),(2,0),(2,1),(2,2),(1,2),(1,1),(0,1),(0,2),(0,3),(1,3),(2,3)

solution/0900-0999/0981.Time Based Key-Value Store/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,10 @@ tags:
4141

4242
<strong>解释:</strong>
4343
TimeMap timeMap = new TimeMap();
44-
timeMap.set("foo", "bar", 1); // 存储键 "foo" 和值 "bar" ,时间戳 timestamp = 1 &nbsp;
44+
timeMap.set("foo", "bar", 1); // 存储键 "foo" 和值 "bar" ,时间戳 timestamp = 1 &nbsp;
4545
timeMap.get("foo", 1); // 返回 "bar"
4646
timeMap.get("foo", 3); // 返回 "bar", 因为在时间戳 3 和时间戳 2 处没有对应 "foo" 的值,所以唯一的值位于时间戳 1 处(即 "bar") 。
47-
timeMap.set("foo", "bar2", 4); // 存储键 "foo" 和值 "bar2" ,时间戳 timestamp = 4&nbsp;
47+
timeMap.set("foo", "bar2", 4); // 存储键 "foo" 和值 "bar2" ,时间戳 timestamp = 4&nbsp;
4848
timeMap.get("foo", 4); // 返回 "bar2"
4949
timeMap.get("foo", 5); // 返回 "bar2"
5050
</pre>

solution/1200-1299/1261.Find Elements in a Contaminated Binary Tree/README.md

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,12 @@ tags:
2727

2828
<ol>
2929
<li><code>root.val == 0</code></li>
30-
<li>如果 <code>treeNode.val == x</code> 且&nbsp;<code>treeNode.left != null</code>,那么&nbsp;<code>treeNode.left.val == 2 * x + 1</code></li>
31-
<li>如果 <code>treeNode.val == x</code> 且 <code>treeNode.right != null</code>,那么&nbsp;<code>treeNode.right.val == 2 * x + 2</code></li>
30+
<li>对于任意 <code>treeNode</code>:
31+
<ol type="a">
32+
<li>如果 <code>treeNode.val</code> 为&nbsp;<code>x</code> 且&nbsp;<code>treeNode.left != null</code>,那么&nbsp;<code>treeNode.left.val == 2 * x + 1</code></li>
33+
<li>如果 <code>treeNode.val</code> 为&nbsp;<code>x</code> 且 <code>treeNode.right != null</code>,那么&nbsp;<code>treeNode.right.val == 2 * x + 2</code></li>
34+
</ol>
35+
</li>
3236
</ol>
3337

3438
<p>现在这个二叉树受到「污染」,所有的&nbsp;<code>treeNode.val</code>&nbsp;都变成了&nbsp;<code>-1</code>。</p>
@@ -42,12 +46,13 @@ tags:
4246

4347
<p>&nbsp;</p>
4448

45-
<p><strong>示例 1:</strong></p>
49+
<p><strong class="example">示例 1:</strong></p>
4650

47-
<p><strong><img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/1200-1299/1261.Find%20Elements%20in%20a%20Contaminated%20Binary%20Tree/images/untitled-diagram-4-1.jpg" style="height: 119px; width: 320px;"></strong></p>
51+
<p><strong><img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/1200-1299/1261.Find%20Elements%20in%20a%20Contaminated%20Binary%20Tree/images/untitled-diagram-4-1.jpg" style="height: 119px; width: 320px;" /></strong></p>
4852

49-
<pre><strong>输入:</strong>
50-
[&quot;FindElements&quot;,&quot;find&quot;,&quot;find&quot;]
53+
<pre>
54+
<strong>输入:</strong>
55+
["FindElements","find","find"]
5156
[[[-1,null,-1]],[1],[2]]
5257
<strong>输出:</strong>
5358
[null,false,true]
@@ -56,12 +61,13 @@ FindElements findElements = new FindElements([-1,null,-1]);
5661
findElements.find(1); // return False
5762
findElements.find(2); // return True </pre>
5863

59-
<p><strong>示例 2:</strong></p>
64+
<p><strong class="example">示例 2:</strong></p>
6065

61-
<p><strong><img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/1200-1299/1261.Find%20Elements%20in%20a%20Contaminated%20Binary%20Tree/images/untitled-diagram-4.jpg" style="height: 198px; width: 400px;"></strong></p>
66+
<p><strong><img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/1200-1299/1261.Find%20Elements%20in%20a%20Contaminated%20Binary%20Tree/images/untitled-diagram-4.jpg" style="height: 198px; width: 400px;" /></strong></p>
6267

63-
<pre><strong>输入:</strong>
64-
[&quot;FindElements&quot;,&quot;find&quot;,&quot;find&quot;,&quot;find&quot;]
68+
<pre>
69+
<strong>输入:</strong>
70+
["FindElements","find","find","find"]
6571
[[[-1,-1,-1,-1,-1]],[1],[3],[5]]
6672
<strong>输出:</strong>
6773
[null,true,true,false]
@@ -71,12 +77,13 @@ findElements.find(1); // return True
7177
findElements.find(3); // return True
7278
findElements.find(5); // return False</pre>
7379

74-
<p><strong>示例 3:</strong></p>
80+
<p><strong class="example">示例 3:</strong></p>
7581

76-
<p><strong><img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/1200-1299/1261.Find%20Elements%20in%20a%20Contaminated%20Binary%20Tree/images/untitled-diagram-4-1-1.jpg" style="height: 274px; width: 306px;"></strong></p>
82+
<p><strong><img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/1200-1299/1261.Find%20Elements%20in%20a%20Contaminated%20Binary%20Tree/images/untitled-diagram-4-1-1.jpg" style="height: 274px; width: 306px;" /></strong></p>
7783

78-
<pre><strong>输入:</strong>
79-
[&quot;FindElements&quot;,&quot;find&quot;,&quot;find&quot;,&quot;find&quot;,&quot;find&quot;]
84+
<pre>
85+
<strong>输入:</strong>
86+
["FindElements","find","find","find","find"]
8087
[[[-1,null,-1,-1,null,-1]],[2],[3],[4],[5]]
8188
<strong>输出:</strong>
8289
[null,true,false,false,true]
@@ -95,9 +102,9 @@ findElements.find(5); // return True
95102
<ul>
96103
<li><code>TreeNode.val == -1</code></li>
97104
<li>二叉树的高度不超过&nbsp;<code>20</code></li>
98-
<li>节点的总数在&nbsp;<code>[1,&nbsp;10^4]</code>&nbsp;之间</li>
99-
<li>调用&nbsp;<code>find()</code>&nbsp;的总次数在&nbsp;<code>[1,&nbsp;10^4]</code>&nbsp;之间</li>
100-
<li><code>0 &lt;= target &lt;= 10^6</code></li>
105+
<li>节点的总数在&nbsp;<code>[1,&nbsp;10<sup>4</sup>]</code>&nbsp;之间</li>
106+
<li>调用&nbsp;<code>find()</code>&nbsp;的总次数在&nbsp;<code>[1,&nbsp;10<sup>4</sup>]</code>&nbsp;之间</li>
107+
<li><code>0 &lt;= target &lt;= 10<sup>6</sup></code></li>
101108
</ul>
102109

103110
<!-- description:end -->

solution/1200-1299/1261.Find Elements in a Contaminated Binary Tree/README_EN.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,12 @@ tags:
2727

2828
<ol>
2929
<li><code>root.val == 0</code></li>
30-
<li>If <code>treeNode.val == x</code> and <code>treeNode.left != null</code>, then <code>treeNode.left.val == 2 * x + 1</code></li>
31-
<li>If <code>treeNode.val == x</code> and <code>treeNode.right != null</code>, then <code>treeNode.right.val == 2 * x + 2</code></li>
30+
<li>For any <code>treeNode</code>:
31+
<ol type="a">
32+
<li>If <code>treeNode.val</code> has a value <code>x</code> and <code>treeNode.left != null</code>, then <code>treeNode.left.val == 2 * x + 1</code></li>
33+
<li>If <code>treeNode.val</code> has a value <code>x</code> and <code>treeNode.right != null</code>, then <code>treeNode.right.val == 2 * x + 2</code></li>
34+
</ol>
35+
</li>
3236
</ol>
3337

3438
<p>Now the binary tree is contaminated, which means all <code>treeNode.val</code> have been changed to <code>-1</code>.</p>

solution/1300-1399/1352.Product of the Last K Numbers/README.md

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,29 +22,25 @@ tags:
2222

2323
<!-- description:start -->
2424

25-
<p>请你实现一个「数字乘积类」<code>ProductOfNumbers</code>,要求支持下述两种方法:</p>
25+
<p>设计一个算法,该算法接受一个整数流并检索该流中最后 <code>k</code> 个整数的乘积。</p>
2626

27-
<p>1.<code>&nbsp;add(int num)</code></p>
27+
<p>实现&nbsp;<code>ProductOfNumbers</code>&nbsp;类:</p>
2828

2929
<ul>
30-
<li>将数字&nbsp;<code>num</code>&nbsp;添加到当前数字列表的最后面。</li>
30+
<li><code>ProductOfNumbers()</code>&nbsp;用一个空的流初始化对象。</li>
31+
<li><code>void add(int num)</code>&nbsp;将数字&nbsp;<code>num</code>&nbsp;添加到当前数字列表的最后面。</li>
32+
<li><code>int getProduct(int k)</code>&nbsp;返回当前数字列表中,最后&nbsp;<code>k</code>&nbsp;个数字的乘积。你可以假设当前列表中始终 <strong>至少</strong> 包含 <code>k</code> 个数字。</li>
3133
</ul>
3234

33-
<p>2.<code> getProduct(int k)</code></p>
34-
35-
<ul>
36-
<li>返回当前数字列表中,最后&nbsp;<code>k</code>&nbsp;个数字的乘积。</li>
37-
<li>你可以假设当前列表中始终 <strong>至少</strong> 包含 <code>k</code> 个数字。</li>
38-
</ul>
39-
40-
<p>题目数据保证:任何时候,任一连续数字序列的乘积都在 32-bit 整数范围内,不会溢出。</p>
35+
<p>题目数据保证:任何时候,任一连续数字序列的乘积都在 32 位整数范围内,不会溢出。</p>
4136

4237
<p>&nbsp;</p>
4338

4439
<p><strong>示例:</strong></p>
4540

46-
<pre><strong>输入:</strong>
47-
[&quot;ProductOfNumbers&quot;,&quot;add&quot;,&quot;add&quot;,&quot;add&quot;,&quot;add&quot;,&quot;add&quot;,&quot;getProduct&quot;,&quot;getProduct&quot;,&quot;getProduct&quot;,&quot;add&quot;,&quot;getProduct&quot;]
41+
<pre>
42+
<strong>输入:</strong>
43+
["ProductOfNumbers","add","add","add","add","add","getProduct","getProduct","getProduct","add","getProduct"]
4844
[[],[3],[0],[2],[5],[4],[2],[3],[4],[8],[2]]
4945

5046
<strong>输出:</strong>
@@ -61,19 +57,24 @@ productOfNumbers.getProduct(2); // 返回 20 。最后 2 个数字的乘积是 5
6157
productOfNumbers.getProduct(3); // 返回 40 。最后 3 个数字的乘积是 2 * 5 * 4 = 40
6258
productOfNumbers.getProduct(4); // 返回 0 。最后 4 个数字的乘积是 0 * 2 * 5 * 4 = 0
6359
productOfNumbers.add(8); // [3,0,2,5,4,8]
64-
productOfNumbers.getProduct(2); // 返回 32 。最后 2 个数字的乘积是 4 * 8 = 32
60+
productOfNumbers.getProduct(2); // 返回 32 。最后 2 个数字的乘积是 4 * 8 = 32
6561
</pre>
6662

6763
<p>&nbsp;</p>
6864

6965
<p><strong>提示:</strong></p>
7066

7167
<ul>
72-
<li><code>add</code> 和 <code>getProduct</code>&nbsp;两种操作加起来总共不会超过&nbsp;<code>40000</code>&nbsp;次。</li>
7368
<li><code>0 &lt;= num&nbsp;&lt;=&nbsp;100</code></li>
74-
<li><code>1 &lt;= k &lt;= 40000</code></li>
69+
<li><code>1 &lt;= k &lt;= 4 * 10<sup>4</sup></code></li>
70+
<li><code>add</code> 和 <code>getProduct</code>&nbsp;最多被调用&nbsp;<code>4 * 10<sup>4</sup></code> 次。</li>
71+
<li>在任何时间点流的乘积都在 32 位整数范围内。</li>
7572
</ul>
7673

74+
<p>&nbsp;</p>
75+
76+
<p><strong>进阶:</strong>您能否 <strong>同时</strong> 将 <code>GetProduct</code> 和 <code>Add</code> 的实现改为 <code>O(1)</code> 时间复杂度,而不是 <code>O(k)</code> 时间复杂度?</p>
77+
7778
<!-- description:end -->
7879

7980
## 解法

solution/1300-1399/1352.Product of the Last K Numbers/README_EN.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ productOfNumbers.getProduct(2); // return 20. The product of the last 2 numbers
5656
productOfNumbers.getProduct(3); // return 40. The product of the last 3 numbers is 2 * 5 * 4 = 40
5757
productOfNumbers.getProduct(4); // return 0. The product of the last 4 numbers is 0 * 2 * 5 * 4 = 0
5858
productOfNumbers.add(8); // [3,0,2,5,4,8]
59-
productOfNumbers.getProduct(2); // return 32. The product of the last 2 numbers is 4 * 8 = 32
59+
productOfNumbers.getProduct(2); // return 32. The product of the last 2 numbers is 4 * 8 = 32
6060
</pre>
6161

6262
<p>&nbsp;</p>
@@ -69,6 +69,9 @@ productOfNumbers.getProduct(2); // return 32. The product of the last 2 numbers
6969
<li>The product of the stream at any point in time will fit in a <strong>32-bit</strong> integer.</li>
7070
</ul>
7171

72+
<p>&nbsp;</p>
73+
<strong>Follow-up: </strong>Can you implement <strong>both</strong> <code>GetProduct</code> and <code>Add</code> to work in <code>O(1)</code> time complexity instead of <code>O(k)</code> time complexity?
74+
7275
<!-- description:end -->
7376

7477
## Solutions

solution/1400-1499/1408.String Matching in an Array/README_EN.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@ tags:
2020

2121
<!-- description:start -->
2222

23-
<p>Given an array of string <code>words</code>, return <em>all strings in </em><code>words</code><em> that is a <strong>substring</strong> of another word</em>. You can return the answer in <strong>any order</strong>.</p>
24-
25-
<p>A <strong>substring</strong> is a contiguous sequence of characters within a string</p>
23+
<p>Given an array of string <code>words</code>, return all strings in<em> </em><code>words</code><em> </em>that are a <span data-keyword="substring-nonempty">substring</span> of another word. You can return the answer in <strong>any order</strong>.</p>
2624

2725
<p>&nbsp;</p>
2826
<p><strong class="example">Example 1:</strong></p>

0 commit comments

Comments
 (0)