Skip to content

Commit 7646741

Browse files
committed
更新国外版新增题目
1 parent bc30d9a commit 7646741

19 files changed

+6353
-4497
lines changed

Diff for: leetcode/origin-data.json

+4,842-4,497
Large diffs are not rendered by default.

Diff for: leetcode/originData/count-lattice-points-inside-a-circle.json

+186
Large diffs are not rendered by default.

Diff for: leetcode/originData/count-number-of-rectangles-containing-each-point.json

+181
Large diffs are not rendered by default.

Diff for: leetcode/originData/count-prefixes-of-a-given-string.json

+154
Large diffs are not rendered by default.

Diff for: leetcode/originData/number-of-flowers-in-full-bloom.json

+194
Large diffs are not rendered by default.

Diff for: leetcode/originData/remove-digit-from-number-to-maximize-result.json

+156
Large diffs are not rendered by default.

Diff for: leetcode/originData/total-appeal-of-a-string.json

+157
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<p>Given a 2D integer array <code>circles</code> where <code>circles[i] = [x<sub>i</sub>, y<sub>i</sub>, r<sub>i</sub>]</code> represents the center <code>(x<sub>i</sub>, y<sub>i</sub>)</code> and radius <code>r<sub>i</sub></code> of the <code>i<sup>th</sup></code> circle drawn on a grid, return <em>the <strong>number of lattice points</strong> </em><em>that are present inside <strong>at least one</strong> circle</em>.</p>
2+
3+
<p><strong>Note:</strong></p>
4+
5+
<ul>
6+
<li>A <strong>lattice point</strong> is a point with integer coordinates.</li>
7+
<li>Points that lie <strong>on the circumference of a circle</strong> are also considered to be inside it.</li>
8+
</ul>
9+
10+
<p>&nbsp;</p>
11+
<p><strong>Example 1:</strong></p>
12+
<img alt="" src="https://assets.leetcode.com/uploads/2022/03/02/exa-11.png" style="width: 300px; height: 300px;" />
13+
<pre>
14+
<strong>Input:</strong> circles = [[2,2,1]]
15+
<strong>Output:</strong> 5
16+
<strong>Explanation:</strong>
17+
The figure above shows the given circle.
18+
The lattice points present inside the circle are (1, 2), (2, 1), (2, 2), (2, 3), and (3, 2) and are shown in green.
19+
Other points such as (1, 1) and (1, 3), which are shown in red, are not considered inside the circle.
20+
Hence, the number of lattice points present inside at least one circle is 5.</pre>
21+
22+
<p><strong>Example 2:</strong></p>
23+
<img alt="" src="https://assets.leetcode.com/uploads/2022/03/02/exa-22.png" style="width: 300px; height: 300px;" />
24+
<pre>
25+
<strong>Input:</strong> circles = [[2,2,2],[3,4,1]]
26+
<strong>Output:</strong> 16
27+
<strong>Explanation:</strong>
28+
The figure above shows the given circles.
29+
There are exactly 16 lattice points which are present inside at least one circle.
30+
Some of them are (0, 2), (2, 0), (2, 4), (3, 2), and (4, 4).
31+
</pre>
32+
33+
<p>&nbsp;</p>
34+
<p><strong>Constraints:</strong></p>
35+
36+
<ul>
37+
<li><code>1 &lt;= circles.length &lt;= 200</code></li>
38+
<li><code>circles[i].length == 3</code></li>
39+
<li><code>1 &lt;= x<sub>i</sub>, y<sub>i</sub> &lt;= 100</code></li>
40+
<li><code>1 &lt;= r<sub>i</sub> &lt;= min(x<sub>i</sub>, y<sub>i</sub>)</code></li>
41+
</ul>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<p>You are given a 2D integer array <code>rectangles</code> where <code>rectangles[i] = [l<sub>i</sub>, h<sub>i</sub>]</code> indicates that <code>i<sup>th</sup></code> rectangle has a length of <code>l<sub>i</sub></code> and a height of <code>h<sub>i</sub></code>. You are also given a 2D integer array <code>points</code> where <code>points[j] = [x<sub>j</sub>, y<sub>j</sub>]</code> is a point with coordinates <code>(x<sub>j</sub>, y<sub>j</sub>)</code>.</p>
2+
3+
<p>The <code>i<sup>th</sup></code> rectangle has its <strong>bottom-left corner</strong> point at the coordinates <code>(0, 0)</code> and its <strong>top-right corner</strong> point at <code>(l<sub>i</sub>, h<sub>i</sub>)</code>.</p>
4+
5+
<p>Return<em> an integer array </em><code>count</code><em> of length </em><code>points.length</code><em> where </em><code>count[j]</code><em> is the number of rectangles that <strong>contain</strong> the </em><code>j<sup>th</sup></code><em> point.</em></p>
6+
7+
<p>The <code>i<sup>th</sup></code> rectangle <strong>contains</strong> the <code>j<sup>th</sup></code> point if <code>0 &lt;= x<sub>j</sub> &lt;= l<sub>i</sub></code> and <code>0 &lt;= y<sub>j</sub> &lt;= h<sub>i</sub></code>. Note that points that lie on the <strong>edges</strong> of a rectangle are also considered to be contained by that rectangle.</p>
8+
9+
<p>&nbsp;</p>
10+
<p><strong>Example 1:</strong></p>
11+
<img alt="" src="https://assets.leetcode.com/uploads/2022/03/02/example1.png" style="width: 300px; height: 509px;" />
12+
<pre>
13+
<strong>Input:</strong> rectangles = [[1,2],[2,3],[2,5]], points = [[2,1],[1,4]]
14+
<strong>Output:</strong> [2,1]
15+
<strong>Explanation:</strong>
16+
The first rectangle contains no points.
17+
The second rectangle contains only the point (2, 1).
18+
The third rectangle contains the points (2, 1) and (1, 4).
19+
The number of rectangles that contain the point (2, 1) is 2.
20+
The number of rectangles that contain the point (1, 4) is 1.
21+
Therefore, we return [2, 1].
22+
</pre>
23+
24+
<p><strong>Example 2:</strong></p>
25+
<img alt="" src="https://assets.leetcode.com/uploads/2022/03/02/example2.png" style="width: 300px; height: 312px;" />
26+
<pre>
27+
<strong>Input:</strong> rectangles = [[1,1],[2,2],[3,3]], points = [[1,3],[1,1]]
28+
<strong>Output:</strong> [1,3]
29+
<strong>Explanation:
30+
</strong>The first rectangle contains only the point (1, 1).
31+
The second rectangle contains only the point (1, 1).
32+
The third rectangle contains the points (1, 3) and (1, 1).
33+
The number of rectangles that contain the point (1, 3) is 1.
34+
The number of rectangles that contain the point (1, 1) is 3.
35+
Therefore, we return [1, 3].
36+
</pre>
37+
38+
<p>&nbsp;</p>
39+
<p><strong>Constraints:</strong></p>
40+
41+
<ul>
42+
<li><code>1 &lt;= rectangles.length, points.length &lt;= 5 * 10<sup>4</sup></code></li>
43+
<li><code>rectangles[i].length == points[j].length == 2</code></li>
44+
<li><code>1 &lt;= l<sub>i</sub>, x<sub>j</sub> &lt;= 10<sup>9</sup></code></li>
45+
<li><code>1 &lt;= h<sub>i</sub>, y<sub>j</sub> &lt;= 100</code></li>
46+
<li>All the <code>rectangles</code> are <strong>unique</strong>.</li>
47+
<li>All the <code>points</code> are <strong>unique</strong>.</li>
48+
</ul>
+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<p>You are given a string array <code>words</code> and a string <code>s</code>, where <code>words[i]</code> and <code>s</code> comprise only of <strong>lowercase English letters</strong>.</p>
2+
3+
<p>Return <em>the <strong>number of strings</strong> in</em> <code>words</code> <em>that are a <strong>prefix</strong> of</em> <code>s</code>.</p>
4+
5+
<p>A <strong>prefix</strong> of a string is a substring that occurs at the beginning of the string. A <b>substring</b> is a contiguous sequence of characters within a string.</p>
6+
7+
<p>&nbsp;</p>
8+
<p><strong>Example 1:</strong></p>
9+
10+
<pre>
11+
<strong>Input:</strong> words = [&quot;a&quot;,&quot;b&quot;,&quot;c&quot;,&quot;ab&quot;,&quot;bc&quot;,&quot;abc&quot;], s = &quot;abc&quot;
12+
<strong>Output:</strong> 3
13+
<strong>Explanation:</strong>
14+
The strings in words which are a prefix of s = &quot;abc&quot; are:
15+
&quot;a&quot;, &quot;ab&quot;, and &quot;abc&quot;.
16+
Thus the number of strings in words which are a prefix of s is 3.</pre>
17+
18+
<p><strong>Example 2:</strong></p>
19+
20+
<pre>
21+
<strong>Input:</strong> words = [&quot;a&quot;,&quot;a&quot;], s = &quot;aa&quot;
22+
<strong>Output:</strong> 2
23+
<strong>Explanation:
24+
</strong>Both of the strings are a prefix of s.
25+
Note that the same string can occur multiple times in words, and it should be counted each time.</pre>
26+
27+
<p>&nbsp;</p>
28+
<p><strong>Constraints:</strong></p>
29+
30+
<ul>
31+
<li><code>1 &lt;= words.length &lt;= 1000</code></li>
32+
<li><code>1 &lt;= words[i].length, s.length &lt;= 10</code></li>
33+
<li><code>words[i]</code> and <code>s</code> consist of lowercase English letters <strong>only</strong>.</li>
34+
</ul>
+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<p>You are given two integers <code>m</code> and <code>n</code> representing a <strong>0-indexed</strong> <code>m x n</code> grid. You are also given two 2D integer arrays <code>guards</code> and <code>walls</code> where <code>guards[i] = [row<sub>i</sub>, col<sub>i</sub>]</code> and <code>walls[j] = [row<sub>j</sub>, col<sub>j</sub>]</code> represent the positions of the <code>i<sup>th</sup></code> guard and <code>j<sup>th</sup></code> wall respectively.</p>
2+
3+
<p>A guard can see <b>every</b> cell in the four cardinal directions (north, east, south, or west) starting from their position unless <strong>obstructed</strong> by a wall or another guard. A cell is <strong>guarded</strong> if there is <strong>at least</strong> one guard that can see it.</p>
4+
5+
<p>Return<em> the number of unoccupied cells that are <strong>not</strong> <strong>guarded</strong>.</em></p>
6+
7+
<p>&nbsp;</p>
8+
<p><strong>Example 1:</strong></p>
9+
<img alt="" src="https://assets.leetcode.com/uploads/2022/03/10/example1drawio2.png" style="width: 300px; height: 204px;" />
10+
<pre>
11+
<strong>Input:</strong> m = 4, n = 6, guards = [[0,0],[1,1],[2,3]], walls = [[0,1],[2,2],[1,4]]
12+
<strong>Output:</strong> 7
13+
<strong>Explanation:</strong> The guarded and unguarded cells are shown in red and green respectively in the above diagram.
14+
There are a total of 7 unguarded cells, so we return 7.
15+
</pre>
16+
17+
<p><strong>Example 2:</strong></p>
18+
<img alt="" src="https://assets.leetcode.com/uploads/2022/03/10/example2drawio.png" style="width: 200px; height: 201px;" />
19+
<pre>
20+
<strong>Input:</strong> m = 3, n = 3, guards = [[1,1]], walls = [[0,1],[1,0],[2,1],[1,2]]
21+
<strong>Output:</strong> 4
22+
<strong>Explanation:</strong> The unguarded cells are shown in green in the above diagram.
23+
There are a total of 4 unguarded cells, so we return 4.
24+
</pre>
25+
26+
<p>&nbsp;</p>
27+
<p><strong>Constraints:</strong></p>
28+
29+
<ul>
30+
<li><code>1 &lt;= m, n &lt;= 10<sup>5</sup></code></li>
31+
<li><code>2 &lt;= m * n &lt;= 10<sup>5</sup></code></li>
32+
<li><code>1 &lt;= guards.length, walls.length &lt;= 5 * 10<sup>4</sup></code></li>
33+
<li><code>2 &lt;= guards.length + walls.length &lt;= m * n</code></li>
34+
<li><code>guards[i].length == walls[j].length == 2</code></li>
35+
<li><code>0 &lt;= row<sub>i</sub>, row<sub>j</sub> &lt; m</code></li>
36+
<li><code>0 &lt;= col<sub>i</sub>, col<sub>j</sub> &lt; n</code></li>
37+
<li>All the positions in <code>guards</code> and <code>walls</code> are <strong>unique</strong>.</li>
38+
</ul>

Diff for: leetcode/problem/escape-the-spreading-fire.html

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<p>You are given a <strong>0-indexed</strong> 2D integer array <code>grid</code> of size <code>m x n</code> which represents a field. Each cell has one of three values:</p>
2+
3+
<ul>
4+
<li><code>0</code> represents grass,</li>
5+
<li><code>1</code> represents fire,</li>
6+
<li><code>2</code> represents a wall that you and fire cannot pass through.</li>
7+
</ul>
8+
9+
<p>You are situated in the top-left cell, <code>(0, 0)</code>, and you want to travel to the safehouse at the bottom-right cell, <code>(m - 1, n - 1)</code>. Every minute, you may move to an <strong>adjacent</strong> grass cell. <strong>After</strong> your move, every fire cell will spread to all <strong>adjacent</strong> cells that are not walls.</p>
10+
11+
<p>Return <em>the <strong>maximum</strong> number of minutes that you can stay in your initial position before moving while still safely reaching the safehouse</em>. If this is impossible, return <code>-1</code>. If you can <strong>always</strong> reach the safehouse regardless of the minutes stayed, return <code>10<sup>9</sup></code>.</p>
12+
13+
<p>Note that even if the fire spreads to the safehouse immediately after you have reached it, it will be counted as safely reaching the safehouse.</p>
14+
15+
<p>A cell is <strong>adjacent</strong> to another cell if the former is directly north, east, south, or west of the latter (i.e., their sides are touching).</p>
16+
17+
<p>&nbsp;</p>
18+
<p><strong>Example 1:</strong></p>
19+
<img alt="" src="https://assets.leetcode.com/uploads/2022/03/10/ex1new.jpg" style="width: 650px; height: 404px;" />
20+
<pre>
21+
<strong>Input:</strong> grid = [[0,2,0,0,0,0,0],[0,0,0,2,2,1,0],[0,2,0,0,1,2,0],[0,0,2,2,2,0,2],[0,0,0,0,0,0,0]]
22+
<strong>Output:</strong> 3
23+
<strong>Explanation:</strong> The figure above shows the scenario where you stay in the initial position for 3 minutes.
24+
You will still be able to safely reach the safehouse.
25+
Staying for more than 3 minutes will not allow you to safely reach the safehouse.</pre>
26+
27+
<p><strong>Example 2:</strong></p>
28+
<img alt="" src="https://assets.leetcode.com/uploads/2022/03/10/ex2new2.jpg" style="width: 515px; height: 150px;" />
29+
<pre>
30+
<strong>Input:</strong> grid = [[0,0,0,0],[0,1,2,0],[0,2,0,0]]
31+
<strong>Output:</strong> -1
32+
<strong>Explanation:</strong> The figure above shows the scenario where you immediately move towards the safehouse.
33+
Fire will spread to any cell you move towards and it is impossible to safely reach the safehouse.
34+
Thus, -1 is returned.
35+
</pre>
36+
37+
<p><strong>Example 3:</strong></p>
38+
<img alt="" src="https://assets.leetcode.com/uploads/2022/03/10/ex3new.jpg" style="width: 174px; height: 150px;" />
39+
<pre>
40+
<strong>Input:</strong> grid = [[0,0,0],[2,2,0],[1,2,0]]
41+
<strong>Output:</strong> 1000000000
42+
<strong>Explanation:</strong> The figure above shows the initial grid.
43+
Notice that the fire is contained by walls and you will always be able to safely reach the safehouse.
44+
Thus, 10<sup>9</sup> is returned.
45+
</pre>
46+
47+
<p>&nbsp;</p>
48+
<p><strong>Constraints:</strong></p>
49+
50+
<ul>
51+
<li><code>m == grid.length</code></li>
52+
<li><code>n == grid[i].length</code></li>
53+
<li><code>2 &lt;= m, n &lt;= 300</code></li>
54+
<li><code>4 &lt;= m * n &lt;= 2 * 10<sup>4</sup></code></li>
55+
<li><code>grid[i][j]</code> is either <code>0</code>, <code>1</code>, or <code>2</code>.</li>
56+
<li><code>grid[0][0] == grid[m - 1][n - 1] == 0</code></li>
57+
</ul>
+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
Given a 2D integer array <code>nums</code> where <code>nums[i]</code> is a non-empty array of <strong>distinct</strong> positive integers, return <em>the list of integers that are present in <strong>each array</strong> of</em> <code>nums</code><em> sorted in <strong>ascending order</strong></em>.
2+
<p>&nbsp;</p>
3+
<p><strong>Example 1:</strong></p>
4+
5+
<pre>
6+
<strong>Input:</strong> nums = [[<u><strong>3</strong></u>,1,2,<u><strong>4</strong></u>,5],[1,2,<u><strong>3</strong></u>,<u><strong>4</strong></u>],[<u><strong>3</strong></u>,<u><strong>4</strong></u>,5,6]]
7+
<strong>Output:</strong> [3,4]
8+
<strong>Explanation:</strong>
9+
The only integers present in each of nums[0] = [<u><strong>3</strong></u>,1,2,<u><strong>4</strong></u>,5], nums[1] = [1,2,<u><strong>3</strong></u>,<u><strong>4</strong></u>], and nums[2] = [<u><strong>3</strong></u>,<u><strong>4</strong></u>,5,6] are 3 and 4, so we return [3,4].</pre>
10+
11+
<p><strong>Example 2:</strong></p>
12+
13+
<pre>
14+
<strong>Input:</strong> nums = [[1,2,3],[4,5,6]]
15+
<strong>Output:</strong> []
16+
<strong>Explanation:</strong>
17+
There does not exist any integer present both in nums[0] and nums[1], so we return an empty list [].
18+
</pre>
19+
20+
<p>&nbsp;</p>
21+
<p><strong>Constraints:</strong></p>
22+
23+
<ul>
24+
<li><code>1 &lt;= nums.length &lt;= 1000</code></li>
25+
<li><code>1 &lt;= sum(nums[i].length) &lt;= 1000</code></li>
26+
<li><code>1 &lt;= nums[i][j] &lt;= 1000</code></li>
27+
<li>All the values of <code>nums[i]</code> are <strong>unique</strong>.</li>
28+
</ul>

Diff for: leetcode/problem/k-divisible-elements-subarrays.html

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<p>Given an integer array <code>nums</code> and two integers <code>k</code> and <code>p</code>, return <em>the number of <strong>distinct subarrays</strong> which have <strong>at most</strong></em> <code>k</code> <em>elements divisible by</em> <code>p</code>.</p>
2+
3+
<p>Two arrays <code>nums1</code> and <code>nums2</code> are said to be <strong>distinct</strong> if:</p>
4+
5+
<ul>
6+
<li>They are of <strong>different</strong> lengths, or</li>
7+
<li>There exists <strong>at least</strong> one index <code>i</code> where <code>nums1[i] != nums2[i]</code>.</li>
8+
</ul>
9+
10+
<p>A <strong>subarray</strong> is defined as a <strong>non-empty</strong> contiguous sequence of elements in an array.</p>
11+
12+
<p>&nbsp;</p>
13+
<p><strong>Example 1:</strong></p>
14+
15+
<pre>
16+
<strong>Input:</strong> nums = [<u><strong>2</strong></u>,3,3,<u><strong>2</strong></u>,<u><strong>2</strong></u>], k = 2, p = 2
17+
<strong>Output:</strong> 11
18+
<strong>Explanation:</strong>
19+
The elements at indices 0, 3, and 4 are divisible by p = 2.
20+
The 11 distinct subarrays which have at most k = 2 elements divisible by 2 are:
21+
[2], [2,3], [2,3,3], [2,3,3,2], [3], [3,3], [3,3,2], [3,3,2,2], [3,2], [3,2,2], and [2,2].
22+
Note that the subarrays [2] and [3] occur more than once in nums, but they should each be counted only once.
23+
The subarray [2,3,3,2,2] should not be counted because it has 3 elements that are divisible by 2.
24+
</pre>
25+
26+
<p><strong>Example 2:</strong></p>
27+
28+
<pre>
29+
<strong>Input:</strong> nums = [1,2,3,4], k = 4, p = 1
30+
<strong>Output:</strong> 10
31+
<strong>Explanation:</strong>
32+
All element of nums are divisible by p = 1.
33+
Also, every subarray of nums will have at most 4 elements that are divisible by 1.
34+
Since all subarrays are distinct, the total number of subarrays satisfying all the constraints is 10.
35+
</pre>
36+
37+
<p>&nbsp;</p>
38+
<p><strong>Constraints:</strong></p>
39+
40+
<ul>
41+
<li><code>1 &lt;= nums.length &lt;= 200</code></li>
42+
<li><code>1 &lt;= nums[i], p &lt;= 200</code></li>
43+
<li><code>1 &lt;= k &lt;= nums.length</code></li>
44+
</ul>

Diff for: leetcode/problem/minimum-average-difference.html

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<p>You are given a <strong>0-indexed</strong> integer array <code>nums</code> of length <code>n</code>.</p>
2+
3+
<p>The <strong>average difference</strong> of the index <code>i</code> is the <strong>absolute</strong> <strong>difference</strong> between the average of the <strong>first</strong> <code>i + 1</code> elements of <code>nums</code> and the average of the <strong>last</strong> <code>n - i - 1</code> elements. Both averages should be <strong>rounded down</strong> to the nearest integer.</p>
4+
5+
<p>Return<em> the index with the <strong>minimum average difference</strong></em>. If there are multiple such indices, return the <strong>smallest</strong> one.</p>
6+
7+
<p><strong>Note:</strong></p>
8+
9+
<ul>
10+
<li>The <strong>absolute difference</strong> of two numbers is the absolute value of their difference.</li>
11+
<li>The <strong>average</strong> of <code>n</code> elements is the <strong>sum</strong> of the <code>n</code> elements divided (<strong>integer division</strong>) by <code>n</code>.</li>
12+
<li>The average of <code>0</code> elements is considered to be <code>0</code>.</li>
13+
</ul>
14+
15+
<p>&nbsp;</p>
16+
<p><strong>Example 1:</strong></p>
17+
18+
<pre>
19+
<strong>Input:</strong> nums = [2,5,3,9,5,3]
20+
<strong>Output:</strong> 3
21+
<strong>Explanation:</strong>
22+
- The average difference of index 0 is: |2 / 1 - (5 + 3 + 9 + 5 + 3) / 5| = |2 / 1 - 25 / 5| = |2 - 5| = 3.
23+
- The average difference of index 1 is: |(2 + 5) / 2 - (3 + 9 + 5 + 3) / 4| = |7 / 2 - 20 / 4| = |3 - 5| = 2.
24+
- The average difference of index 2 is: |(2 + 5 + 3) / 3 - (9 + 5 + 3) / 3| = |10 / 3 - 17 / 3| = |3 - 5| = 2.
25+
- The average difference of index 3 is: |(2 + 5 + 3 + 9) / 4 - (5 + 3) / 2| = |19 / 4 - 8 / 2| = |4 - 4| = 0.
26+
- The average difference of index 4 is: |(2 + 5 + 3 + 9 + 5) / 5 - 3 / 1| = |24 / 5 - 3 / 1| = |4 - 3| = 1.
27+
- The average difference of index 5 is: |(2 + 5 + 3 + 9 + 5 + 3) / 6 - 0| = |27 / 6 - 0| = |4 - 0| = 4.
28+
The average difference of index 3 is the minimum average difference so return 3.
29+
</pre>
30+
31+
<p><strong>Example 2:</strong></p>
32+
33+
<pre>
34+
<strong>Input:</strong> nums = [0]
35+
<strong>Output:</strong> 0
36+
<strong>Explanation:</strong>
37+
The only index is 0 so return 0.
38+
The average difference of index 0 is: |0 / 1 - 0| = |0 - 0| = 0.
39+
</pre>
40+
41+
<p>&nbsp;</p>
42+
<p><strong>Constraints:</strong></p>
43+
44+
<ul>
45+
<li><code>1 &lt;= nums.length &lt;= 10<sup>5</sup></code></li>
46+
<li><code>0 &lt;= nums[i] &lt;= 10<sup>5</sup></code></li>
47+
</ul>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<p>You are given an integer array <code>cards</code> where <code>cards[i]</code> represents the <strong>value</strong> of the <code>i<sup>th</sup></code> card. A pair of cards are <strong>matching</strong> if the cards have the <strong>same</strong> value.</p>
2+
3+
<p>Return<em> the <strong>minimum</strong> number of <strong>consecutive</strong> cards you have to pick up to have a pair of <strong>matching</strong> cards among the picked cards.</em> If it is impossible to have matching cards, return <code>-1</code>.</p>
4+
5+
<p>&nbsp;</p>
6+
<p><strong>Example 1:</strong></p>
7+
8+
<pre>
9+
<strong>Input:</strong> cards = [3,4,2,3,4,7]
10+
<strong>Output:</strong> 4
11+
<strong>Explanation:</strong> We can pick up the cards [3,4,2,3] which contain a matching pair of cards with value 3. Note that picking up the cards [4,2,3,4] is also optimal.
12+
</pre>
13+
14+
<p><strong>Example 2:</strong></p>
15+
16+
<pre>
17+
<strong>Input:</strong> cards = [1,0,5,3]
18+
<strong>Output:</strong> -1
19+
<strong>Explanation:</strong> There is no way to pick up a set of consecutive cards that contain a pair of matching cards.
20+
</pre>
21+
22+
<p>&nbsp;</p>
23+
<p><strong>Constraints:</strong></p>
24+
25+
<ul>
26+
<li><code>1 &lt;= cards.length &lt;= 10<sup>5</sup></code></li>
27+
<li><code>0 &lt;= cards[i] &lt;= 10<sup>6</sup></code></li>
28+
</ul>

0 commit comments

Comments
 (0)