Skip to content

Commit 7849c5b

Browse files
authored
feat: add weekly contest 437 & biweekly contest 150 (#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

+1-1
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

+1-1
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

+1-1
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

+2-2
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

+2-2
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

+24-17
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

+6-2
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

+17-16
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

+4-1
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

+1-3
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>

solution/1700-1799/1730.Shortest Path to Get Food/README_EN.md

+6
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,12 @@ tags:
5757
<strong>Output:</strong> 6
5858
<strong>Explanation:</strong> There can be multiple food cells. It only takes 6 steps to reach the bottom food.</pre>
5959

60+
<p><strong class="example">Example 4:</strong></p>
61+
62+
<pre>
63+
<strong>Input:</strong> grid = [[&quot;X&quot;,&quot;X&quot;,&quot;X&quot;,&quot;X&quot;,&quot;X&quot;,&quot;X&quot;,&quot;X&quot;,&quot;X&quot;],[&quot;X&quot;,&quot;*&quot;,&quot;O&quot;,&quot;X&quot;,&quot;O&quot;,&quot;#&quot;,&quot;O&quot;,&quot;X&quot;],[&quot;X&quot;,&quot;O&quot;,&quot;O&quot;,&quot;X&quot;,&quot;O&quot;,&quot;O&quot;,&quot;X&quot;,&quot;X&quot;],[&quot;X&quot;,&quot;O&quot;,&quot;O&quot;,&quot;O&quot;,&quot;O&quot;,&quot;#&quot;,&quot;O&quot;,&quot;X&quot;],[&quot;O&quot;,&quot;O&quot;,&quot;O&quot;,&quot;O&quot;,&quot;O&quot;,&quot;O&quot;,&quot;O&quot;,&quot;O&quot;]]
64+
<strong>Output:</strong> 5</pre>
65+
6066
<p>&nbsp;</p>
6167
<p><strong>Constraints:</strong></p>
6268

solution/1700-1799/1752.Check if Array Is Sorted and Rotated/README_EN.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ tags:
2222

2323
<p>There may be <strong>duplicates</strong> in the original array.</p>
2424

25-
<p><strong>Note:</strong> An array <code>A</code> rotated by <code>x</code> positions results in an array <code>B</code> of the same length such that <code>A[i] == B[(i+x) % A.length]</code>, where <code>%</code> is the modulo operation.</p>
25+
<p><strong>Note:</strong> An array <code>A</code> rotated by <code>x</code> positions results in an array <code>B</code> of the same length such that <code>B[i] == A[(i+x) % A.length]</code> for every valid index <code>i</code>.</p>
2626

2727
<p>&nbsp;</p>
2828
<p><strong class="example">Example 1:</strong></p>

solution/1800-1899/1800.Maximum Ascending Subarray Sum/README_EN.md

+1-3
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,10 @@ tags:
1818

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

21-
<p>Given an array of positive integers <code>nums</code>, return the <em>maximum possible sum of an <strong>ascending</strong> subarray in </em><code>nums</code>.</p>
21+
<p>Given an array of positive integers <code>nums</code>, return the <strong>maximum</strong> possible sum of an <span data-keyword="strictly-increasing-array">strictly increasing subarray</span> in<em> </em><code>nums</code>.</p>
2222

2323
<p>A subarray is defined as a contiguous sequence of numbers in an array.</p>
2424

25-
<p>A subarray <code>[nums<sub>l</sub>, nums<sub>l+1</sub>, ..., nums<sub>r-1</sub>, nums<sub>r</sub>]</code> is <strong>ascending</strong> if for all <code>i</code> where <code>l &lt;= i &lt; r</code>, <code>nums<sub>i </sub> &lt; nums<sub>i+1</sub></code>. Note that a subarray of size <code>1</code> is <strong>ascending</strong>.</p>
26-
2725
<p>&nbsp;</p>
2826
<p><strong class="example">Example 1:</strong></p>
2927

solution/1800-1899/1852.Distinct Numbers in Each Subarray/README_EN.md

+13-35
Original file line numberDiff line numberDiff line change
@@ -18,64 +18,42 @@ tags:
1818

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

21-
<p>Given an integer array <code>nums</code> and an integer <code>k</code>, you are asked to construct the array <code>ans</code> of size <code>n-k+1</code> where <code>ans[i]</code> is the number of <strong>distinct</strong> numbers in the subarray <code>nums[i:i+k-1] = [nums[i], nums[i+1], ..., nums[i+k-1]]</code>.</p>
21+
<p>You are given an integer array <code>nums</code> of length <code>n</code> and an integer <code>k</code>. Your task is to find the number of <strong>distinct</strong> elements in <strong>every</strong> subarray of size <code>k</code> within <code>nums</code>.</p>
2222

23-
<p>Return <em>the array </em><code>ans</code>.</p>
23+
<p>Return an array <code>ans</code> such that <code>ans[i]</code> is the count of distinct elements in <code>nums[i..(i + k - 1)]</code> for each index <code>0 &lt;= i &lt; n - k</code>.</p>
2424

2525
<p>&nbsp;</p>
26-
2726
<p><strong class="example">Example 1:</strong></p>
2827

2928
<pre>
30-
3129
<strong>Input:</strong> nums = [1,2,3,2,2,1,3], k = 3
32-
3330
<strong>Output:</strong> [3,2,2,2,3]
34-
3531
<strong>Explanation: </strong>The number of distinct elements in each subarray goes as follows:
36-
37-
- nums[0:2] = [1,2,3] so ans[0] = 3
38-
39-
- nums[1:3] = [2,3,2] so ans[1] = 2
40-
41-
- nums[2:4] = [3,2,2] so ans[2] = 2
42-
43-
- nums[3:5] = [2,2,1] so ans[3] = 2
44-
45-
- nums[4:6] = [2,1,3] so ans[4] = 3
46-
32+
- nums[0..2] = [1,2,3] so ans[0] = 3
33+
- nums[1..3] = [2,3,2] so ans[1] = 2
34+
- nums[2..4] = [3,2,2] so ans[2] = 2
35+
- nums[3..5] = [2,2,1] so ans[3] = 2
36+
- nums[4..6] = [2,1,3] so ans[4] = 3
4737
</pre>
4838

4939
<p><strong class="example">Example 2:</strong></p>
5040

5141
<pre>
52-
5342
<strong>Input:</strong> nums = [1,1,1,1,2,3,4], k = 4
54-
5543
<strong>Output:</strong> [1,2,3,4]
56-
5744
<strong>Explanation: </strong>The number of distinct elements in each subarray goes as follows:
58-
59-
- nums[0:3] = [1,1,1,1] so ans[0] = 1
60-
61-
- nums[1:4] = [1,1,1,2] so ans[1] = 2
62-
63-
- nums[2:5] = [1,1,2,3] so ans[2] = 3
64-
65-
- nums[3:6] = [1,2,3,4] so ans[3] = 4
66-
45+
- nums[0..3] = [1,1,1,1] so ans[0] = 1
46+
- nums[1..4] = [1,1,1,2] so ans[1] = 2
47+
- nums[2..5] = [1,1,2,3] so ans[2] = 3
48+
- nums[3..6] = [1,2,3,4] so ans[3] = 4
6749
</pre>
6850

6951
<p>&nbsp;</p>
70-
7152
<p><strong>Constraints:</strong></p>
7253

7354
<ul>
74-
75-
<li><code>1 &lt;= k &lt;= nums.length &lt;= 10<sup>5</sup></code></li>
76-
77-
<li><code>1 &lt;= nums[i] &lt;= 10<sup>5</sup></code></li>
78-
55+
<li><code>1 &lt;= k &lt;= nums.length &lt;= 10<sup>5</sup></code></li>
56+
<li><code>1 &lt;= nums[i] &lt;= 10<sup>5</sup></code></li>
7957
</ul>
8058

8159
<!-- description:end -->

solution/1900-1999/1976.Number of Ways to Arrive at Destination/README_EN.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ tags:
2929

3030
<p>&nbsp;</p>
3131
<p><strong class="example">Example 1:</strong></p>
32-
<img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/1900-1999/1976.Number%20of%20Ways%20to%20Arrive%20at%20Destination/images/graph2.png" style="width: 235px; height: 381px;" />
32+
<img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/1900-1999/1976.Number%20of%20Ways%20to%20Arrive%20at%20Destination/images/1976_corrected.png" style="width: 255px; height: 400px;" />
3333
<pre>
3434
<strong>Input:</strong> n = 7, roads = [[0,6,7],[0,1,2],[1,2,3],[1,3,3],[6,3,3],[3,5,1],[6,5,1],[2,5,1],[0,4,5],[4,6,2]]
3535
<strong>Output:</strong> 4
Loading

0 commit comments

Comments
 (0)