Skip to content

Commit 6aad117

Browse files
authored
feat: add biweekly contest 124 (doocs#2348)
1 parent c8f62df commit 6aad117

File tree

35 files changed

+1028
-195
lines changed

35 files changed

+1028
-195
lines changed

.github/workflows/deploy.yml

+14-14
Original file line numberDiff line numberDiff line change
@@ -54,18 +54,18 @@ jobs:
5454
github_token: ${{ secrets.GITHUB_TOKEN }}
5555
publish_dir: ./site
5656

57-
- name: Sync to gitee.com
58-
uses: wearerequired/git-mirror-action@master
59-
env:
60-
SSH_PRIVATE_KEY: ${{ secrets.RSA_PRIVATE_KEY }}
61-
with:
62-
source-repo: git@github.com:doocs/leetcode.git
63-
destination-repo: git@gitee.com:Doocs/leetcode.git
57+
# - name: Sync to gitee.com
58+
# uses: wearerequired/git-mirror-action@master
59+
# env:
60+
# SSH_PRIVATE_KEY: ${{ secrets.RSA_PRIVATE_KEY }}
61+
# with:
62+
# source-repo: git@github.com:doocs/leetcode.git
63+
# destination-repo: git@gitee.com:Doocs/leetcode.git
6464

65-
- name: Build Gitee Pages
66-
uses: yanglbme/gitee-pages-action@main
67-
with:
68-
gitee-username: yanglbme
69-
gitee-password: ${{ secrets.GITEE_PASSWORD }}
70-
gitee-repo: doocs/leetcode
71-
branch: gh-pages
65+
# - name: Build Gitee Pages
66+
# uses: yanglbme/gitee-pages-action@main
67+
# with:
68+
# gitee-username: yanglbme
69+
# gitee-password: ${{ secrets.GITEE_PASSWORD }}
70+
# gitee-repo: doocs/leetcode
71+
# branch: gh-pages

solution/0300-0399/0333.Largest BST Subtree/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# [333. 最大 BST 子树](https://leetcode.cn/problems/largest-bst-subtree)
1+
# [333. 最大二叉搜索子树](https://leetcode.cn/problems/largest-bst-subtree)
22

33
[English Version](/solution/0300-0399/0333.Largest%20BST%20Subtree/README_EN.md)
44

solution/0300-0399/0373.Find K Pairs with Smallest Sums/README_EN.md

-8
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,6 @@
2727
<strong>Explanation:</strong> The first 2 pairs are returned from the sequence: [1,1],[1,1],[1,2],[2,1],[1,2],[2,2],[1,3],[1,3],[2,3]
2828
</pre>
2929

30-
<p><strong class="example">Example 3:</strong></p>
31-
32-
<pre>
33-
<strong>Input:</strong> nums1 = [1,2], nums2 = [3], k = 3
34-
<strong>Output:</strong> [[1,3],[2,3]]
35-
<strong>Explanation:</strong> All possible pairs are returned from the sequence: [1,3],[2,3]
36-
</pre>
37-
3830
<p>&nbsp;</p>
3931
<p><strong>Constraints:</strong></p>
4032

solution/0600-0699/0629.K Inverse Pairs Array/README_EN.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<p>For an integer array <code>nums</code>, an <strong>inverse pair</strong> is a pair of integers <code>[i, j]</code> where <code>0 &lt;= i &lt; j &lt; nums.length</code> and <code>nums[i] &gt; nums[j]</code>.</p>
88

9-
<p>Given two integers n and k, return the number of different arrays consist of numbers from <code>1</code> to <code>n</code> such that there are exactly <code>k</code> <strong>inverse pairs</strong>. Since the answer can be huge, return it <strong>modulo</strong> <code>10<sup>9</sup> + 7</code>.</p>
9+
<p>Given two integers n and k, return the number of different arrays consisting of numbers from <code>1</code> to <code>n</code> such that there are exactly <code>k</code> <strong>inverse pairs</strong>. Since the answer can be huge, return it <strong>modulo</strong> <code>10<sup>9</sup> + 7</code>.</p>
1010

1111
<p>&nbsp;</p>
1212
<p><strong class="example">Example 1:</strong></p>

solution/0900-0999/0935.Knight Dialer/README_EN.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
## Description
66

7-
<p>The chess knight has a <strong>unique movement</strong>,&nbsp;it may move two squares vertically and one square horizontally, or two squares horizontally and one square vertically (with both forming the shape of an <strong>L</strong>). The possible movements of chess knight are shown in this diagaram:</p>
7+
<p>The chess knight has a <strong>unique movement</strong>,&nbsp;it may move two squares vertically and one square horizontally, or two squares horizontally and one square vertically (with both forming the shape of an <strong>L</strong>). The possible movements of chess knight are shown in this diagram:</p>
88

99
<p>A chess knight can move as indicated in the chess diagram below:</p>
1010
<img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/0900-0999/0935.Knight%20Dialer/images/chess.jpg" style="width: 402px; height: 402px;" />

solution/1000-1099/1071.Greatest Common Divisor of Strings/README_EN.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
## Description
66

7-
<p>For two strings <code>s</code> and <code>t</code>, we say &quot;<code>t</code> divides <code>s</code>&quot; if and only if <code>s = t + ... + t</code> (i.e., <code>t</code> is concatenated with itself one or more times).</p>
7+
<p>For two strings <code>s</code> and <code>t</code>, we say &quot;<code>t</code> divides <code>s</code>&quot; if and only if <code>s = t + t + t + ... + t + t</code> (i.e., <code>t</code> is concatenated with itself one or more times).</p>
88

99
<p>Given two strings <code>str1</code> and <code>str2</code>, return <em>the largest string </em><code>x</code><em> such that </em><code>x</code><em> divides both </em><code>str1</code><em> and </em><code>str2</code>.</p>
1010

solution/1000-1099/1074.Number of Submatrices That Sum to Target/README_EN.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
<ul>
4141
<li><code>1 &lt;= matrix.length &lt;= 100</code></li>
4242
<li><code>1 &lt;= matrix[0].length &lt;= 100</code></li>
43-
<li><code>-1000 &lt;= matrix[i] &lt;= 1000</code></li>
43+
<li><code>-1000 &lt;= matrix[i][j] &lt;= 1000</code></li>
4444
<li><code>-10^8 &lt;= target &lt;= 10^8</code></li>
4545
</ul>
4646

solution/1100-1199/1159.Market Analysis II/README_EN.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,11 @@ item_id is the primary key (column with unique values) of this table.
5353

5454
<p>&nbsp;</p>
5555

56-
<p>Write a solution&nbsp;to find for each user, the join date and the number of orders they made as a buyer in <code>2019</code>.</p>
56+
<p>Write a solution to find for each user whether the brand of the second item (by date) they sold is their favorite brand. If a user sold less than two items, report the answer for that user as no. It is guaranteed that no seller sells more than one item in a day.</p>
5757

5858
<p>Return the result table in <strong>any order</strong>.</p>
5959

60-
<p>The&nbsp;result format is in the following example.</p>
60+
<p>The result format is in the following example.</p>
6161

6262
<p>&nbsp;</p>
6363
<p><strong class="example">Example 1:</strong></p>

solution/1400-1499/1403.Minimum Subsequence in Non-Increasing Order/README_EN.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
<pre>
2525
<strong>Input:</strong> nums = [4,4,7,6,7]
2626
<strong>Output:</strong> [7,7,6]
27-
<strong>Explanation:</strong> The subsequence [7,7] has the sum of its elements equal to 14 which is not strictly greater than the sum of elements not included (14 = 4 + 4 + 6). Therefore, the subsequence [7,6,7] is the minimal satisfying the conditions. Note the subsequence has to be returned in non-decreasing order.
27+
<strong>Explanation:</strong> The subsequence [7,7] has the sum of its elements equal to 14 which is not strictly greater than the sum of elements not included (14 = 4 + 4 + 6). Therefore, the subsequence [7,6,7] is the minimal satisfying the conditions. Note the subsequence has to be returned in non-increasing order.
2828
</pre>
2929

3030
<p>&nbsp;</p>

solution/2100-2199/2149.Rearrange Array Elements by Sign/README_EN.md

+3
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ So nums is rearranged to [1,-1].
4848
<li><code>nums</code> consists of <strong>equal</strong> number of positive and negative integers.</li>
4949
</ul>
5050

51+
<p>&nbsp;</p>
52+
It is not required to do the modifications in-place.
53+
5154
## Solutions
5255

5356
### Solution 1

solution/2700-2799/2792.Count Nodes That Are Great Enough/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# [2792. 计算满足条件的节点数](https://leetcode.cn/problems/count-nodes-that-are-great-enough)
1+
# [2792. 计算足够大的节点数](https://leetcode.cn/problems/count-nodes-that-are-great-enough)
22

33
[English Version](/solution/2700-2799/2792.Count%20Nodes%20That%20Are%20Great%20Enough/README_EN.md)
44

@@ -13,7 +13,7 @@
1313
<li>它的值 <strong>大于</strong> 其子树中 <strong>至少</strong> <code>k</code> 个节点的值。</li>
1414
</ul>
1515

16-
<p>返回满足条件的节点数。</p>
16+
<p>返回足够大的节点数。</p>
1717

1818
<p>如果 <code>u == v</code> 或者 <code>v</code> 是 <code>u</code> 的祖先,则节点 <code>u</code> 在节点 <code>v</code> 的 <strong>子树</strong> 中。</p>
1919

solution/2800-2899/2899.Last Visited Integers/README_EN.md

+66-23
Original file line numberDiff line numberDiff line change
@@ -4,46 +4,89 @@
44

55
## Description
66

7-
<p>Given a <strong>0-indexed</strong> array of strings <code>words</code> where <code>words[i]</code> is either a positive integer represented as a string or the string <code>&quot;prev&quot;</code>.</p>
7+
<p>Given an integer array <code>nums</code> where <code>nums[i]</code> is either a positive integer or <code>-1</code>.</p>
88

9-
<p>Start iterating from the beginning of the array; for every <code>&quot;prev&quot;</code> string seen in <code>words</code>, find the <strong>last visited integer</strong> in <code>words</code> which is defined as follows:</p>
9+
<p>We need to find for each <code>-1</code> the respective positive integer, which we call the last visited integer.</p>
10+
11+
<p>To achieve this goal, let&#39;s define two empty arrays: <code>seen</code> and <code>ans</code>.</p>
12+
13+
<p>Start iterating from the beginning of the array <code>nums</code>.</p>
1014

1115
<ul>
12-
<li>Let <code>k</code> be the number of consecutive <code>&quot;prev&quot;</code> strings seen so far (containing the current string). Let <code>nums</code> be the <strong>0-indexed </strong>array of <strong>integers</strong> seen so far and <code>nums_reverse</code> be the reverse of <code>nums</code>, then the integer at <code>(k - 1)<sup>th</sup></code> index of <code>nums_reverse</code> will be the <strong>last visited integer</strong> for this <code>&quot;prev&quot;</code>.</li>
13-
<li>If <code>k</code> is <strong>greater</strong> than the total visited integers, then the last visited integer will be <code>-1</code>.</li>
16+
<li>If a positive integer is encountered, prepend it to the <strong>front</strong> of <code>seen</code>.</li>
17+
<li>If <code>-1</code>&nbsp;is encountered, let <code>k</code> be the number of <strong>consecutive</strong> <code>-1</code>s seen so far (including the current <code>-1</code>),
18+
<ul>
19+
<li>If <code>k</code> is less than or equal to the length of <code>seen</code>, append the <code>k</code>-th element of <code>seen</code> to <code>ans</code>.</li>
20+
<li>If <code>k</code> is strictly greater than the length of <code>seen</code>, append <code>-1</code> to <code>ans</code>.</li>
21+
</ul>
22+
</li>
1423
</ul>
1524

16-
<p>Return <em>an integer array containing the last visited integers.</em></p>
25+
<p>Return <em>the array </em><code>ans</code>.</p>
1726

1827
<p>&nbsp;</p>
1928
<p><strong class="example">Example 1:</strong></p>
2029

21-
<pre>
22-
<strong>Input:</strong> words = [&quot;1&quot;,&quot;2&quot;,&quot;prev&quot;,&quot;prev&quot;,&quot;prev&quot;]
23-
<strong>Output:</strong> [2,1,-1]
24-
<strong>Explanation:</strong>
25-
For &quot;prev&quot; at index = 2, last visited integer will be 2 as here the number of consecutive &quot;prev&quot; strings is 1, and in the array reverse_nums, 2 will be the first element.
26-
For &quot;prev&quot; at index = 3, last visited integer will be 1 as there are a total of two consecutive &quot;prev&quot; strings including this &quot;prev&quot; which are visited, and 1 is the second last visited integer.
27-
For &quot;prev&quot; at index = 4, last visited integer will be -1 as there are a total of three consecutive &quot;prev&quot; strings including this &quot;prev&quot; which are visited, but the total number of integers visited is two.
28-
</pre>
30+
<div class="example-block" style="
31+
border-color: var(--border-tertiary);
32+
border-left-width: 2px;
33+
color: var(--text-secondary);
34+
font-size: .875rem;
35+
line-height: 1.25rem;
36+
margin-bottom: 1rem;
37+
margin-top: 1rem;
38+
overflow: visible;
39+
padding-left: 1rem;
40+
">
41+
<p><strong>Input:</strong> <code>nums = [1,2,-1,-1,-1]</code></p>
42+
43+
<p><strong>Output:</strong> <code>[2,1,-1]</code></p>
44+
45+
<p><strong>Explanation:</strong> Start with <code>seen = []</code> and <code>ans = []</code>.</p>
46+
47+
<ol>
48+
<li>Process <code>nums[0]</code>: The first element in nums is <code>1</code>. We prepend it to the front of <code>seen</code>. Now, <code>seen == [1]</code>.</li>
49+
<li>Process <code>nums[1]</code>: The next element is <code>2</code>. We prepend it to the front of <code>seen</code>. Now, <code>seen == [2, 1]</code>.</li>
50+
<li>Process <code>nums[2]</code>: The next element is <code>-1</code>. This is the first occurrence of <code>-1</code>, so <code>k == 1</code>. We look for the first element in seen. We append <code>2</code> to <code>ans</code>. Now, <code>ans == [2]</code>.</li>
51+
<li>Process <code>nums[3]</code>: Another <code>-1</code>. This is the second consecutive <code>-1</code>, so <code>k == 2</code>. The second element in <code>seen</code> is <code>1</code>, so we append <code>1</code> to <code>ans</code>. Now, <code>ans == [2, 1]</code>.</li>
52+
<li>Process <code>nums[4]</code>: Another <code>-1</code>, the third in a row, making <code>k = 3</code>. However, <code>seen</code> only has two elements (<code>[2, 1]</code>). Since <code>k</code> is greater than the number of elements in <code>seen</code>, we append <code>-1</code> to <code>ans</code>. Finally, <code>ans == [2, 1, -1]</code>.</li>
53+
</ol>
54+
</div>
2955

3056
<p><strong class="example">Example 2:</strong></p>
3157

32-
<pre>
33-
<strong>Input:</strong> words = [&quot;1&quot;,&quot;prev&quot;,&quot;2&quot;,&quot;prev&quot;,&quot;prev&quot;]
34-
<strong>Output:</strong> [1,2,1]
35-
<strong>Explanation:</strong>
36-
For &quot;prev&quot; at index = 1, last visited integer will be 1.
37-
For &quot;prev&quot; at index = 3, last visited integer will be 2.
38-
For &quot;prev&quot; at index = 4, last visited integer will be 1 as there are a total of two consecutive &quot;prev&quot; strings including this &quot;prev&quot; which are visited, and 1 is the second last visited integer.
39-
</pre>
58+
<div class="example-block" style="
59+
border-color: var(--border-tertiary);
60+
border-left-width: 2px;
61+
color: var(--text-secondary);
62+
font-size: .875rem;
63+
line-height: 1.25rem;
64+
margin-bottom: 1rem;
65+
margin-top: 1rem;
66+
overflow: visible;
67+
padding-left: 1rem;
68+
">
69+
<p><strong>Input:</strong> <code>nums = [1,-1,2,-1,-1]</code></p>
70+
71+
<p><strong>Output:</strong> <code>[1,2,1]</code></p>
72+
73+
<p><strong>Explanation:</strong> Start with <code>seen = []</code> and <code>ans = []</code>.</p>
74+
75+
<ol>
76+
<li>Process <code>nums[0]</code>: The first element in nums is <code>1</code>. We prepend it to the front of <code>seen</code>. Now, <code>seen == [1]</code>.</li>
77+
<li>Process <code>nums[1]</code>: The next element is <code>-1</code>. This is the first occurrence of <code>-1</code>, so <code>k == 1</code>. We look for the first element in <code>seen</code>, which is <code>1</code>. Append <code>1</code> to <code>ans</code>. Now, <code>ans == [1]</code>.</li>
78+
<li>Process <code>nums[2]</code>: The next element is <code>2</code>. Prepend this to the front of <code>seen</code>. Now, <code>seen == [2, 1]</code>.</li>
79+
<li>Process <code>nums[3]</code>: The next element is <code>-1</code>. This <code>-1</code> is not consecutive to the first <code>-1</code> since <code>2</code> was in between. Thus, <code>k</code> resets to <code>1</code>. The first element in <code>seen</code> is <code>2</code>, so append <code>2</code> to <code>ans</code>. Now, <code>ans == [1, 2]</code>.</li>
80+
<li>Process <code>nums[4]</code>: Another <code>-1</code>. This is consecutive to the previous <code>-1</code>, so <code>k == 2</code>. The second element in <code>seen</code> is <code>1</code>, append <code>1</code> to <code>ans</code>. Finally, <code>ans == [1, 2, 1]</code>.</li>
81+
</ol>
82+
</div>
4083

4184
<p>&nbsp;</p>
4285
<p><strong>Constraints:</strong></p>
4386

4487
<ul>
45-
<li><code>1 &lt;= words.length &lt;= 100</code></li>
46-
<li><code>words[i] == &quot;prev&quot;</code> or <code>1 &lt;= int(words[i]) &lt;= 100</code></li>
88+
<li><code>1 &lt;= nums.length &lt;= 100</code></li>
89+
<li><code>nums[i] == -1</code> or <code>1 &lt;= nums[i]&nbsp;&lt;= 100</code></li>
4790
</ul>
4891

4992
## Solutions

0 commit comments

Comments
 (0)