Skip to content

Commit 2ee3b36

Browse files
authored
feat: add weekly contest 427 and biweekly contest 145 (#3846)
1 parent 8a2235a commit 2ee3b36

File tree

53 files changed

+2341
-46
lines changed

Some content is hidden

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

53 files changed

+2341
-46
lines changed

solution/0300-0399/0355.Design Twitter/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ twitter.getNewsFeed(1); // 用户 1 获取推文应当返回一个列表,其
6161
<li><code>0 &lt;= tweetId &lt;= 10<sup>4</sup></code></li>
6262
<li>所有推特的 ID 都互不相同</li>
6363
<li><code>postTweet</code>、<code>getNewsFeed</code>、<code>follow</code> 和 <code>unfollow</code> 方法最多调用 <code>3 * 10<sup>4</sup></code> 次</li>
64+
<li>用户不能关注自己</li>
6465
</ul>
6566

6667
<!-- description:end -->

solution/0300-0399/0355.Design Twitter/README_EN.md

+1
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ twitter.getNewsFeed(1); // User 1&#39;s news feed should return a list with 1 t
6060
<li><code>0 &lt;= tweetId &lt;= 10<sup>4</sup></code></li>
6161
<li>All the tweets have <strong>unique</strong> IDs.</li>
6262
<li>At most <code>3 * 10<sup>4</sup></code> calls will be made to <code>postTweet</code>, <code>getNewsFeed</code>, <code>follow</code>, and <code>unfollow</code>.</li>
63+
<li>A user cannot follow himself.</li>
6364
</ul>
6465

6566
<!-- description:end -->

solution/0700-0799/0782.Transform to Chessboard/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ tags:
9393

9494
若 $n$ 为奇数,那么最终的合法棋盘只有一种可能。如果第一行中 $0$ 的数目大于 $1$,那么最终一盘的第一行只能是“01010...”,否则就是“10101...”。同样算出次数作为答案。
9595

96-
时间复杂度 $O(n^2)$。
96+
时间复杂度 $O(n^2)$,其中 $n$ 是棋盘的大小。空间复杂度 $O(1)$
9797

9898
<!-- tabs:start -->
9999

solution/0700-0799/0782.Transform to Chessboard/README_EN.md

+18-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,24 @@ The second move swaps the second and third row.
6868

6969
<!-- solution:start -->
7070

71-
### Solution 1
71+
### Solution 1: Pattern Observation + State Compression
72+
73+
In a valid chessboard, there are exactly two types of "rows".
74+
75+
For example, if one row on the chessboard is "01010011", then any other row can only be "01010011" or "10101100". Columns also satisfy this property.
76+
77+
Additionally, each row and each column has half $0$s and half $1$s. Suppose the chessboard is $n \times n$:
78+
79+
- If $n = 2 \times k$, then each row and each column has $k$ $1$s and $k$ $0$s.
80+
- If $n = 2 \times k + 1$, then each row has $k$ $1$s and $k + 1$ $0$s, or $k + 1$ $1$s and $k$ $0$s.
81+
82+
Based on the above conclusions, we can determine whether a chessboard is valid. If valid, we can calculate the minimum number of moves required.
83+
84+
If $n$ is even, there are two possible valid chessboards, where the first row is either "010101..." or "101010...". We calculate the minimum number of swaps required for these two possibilities and take the smaller value as the answer.
85+
86+
If $n$ is odd, there is only one possible valid chessboard. If the number of $0$s in the first row is greater than the number of $1$s, then the first row of the final chessboard must be "01010..."; otherwise, it must be "10101...". We calculate the number of swaps required and use it as the answer.
87+
88+
The time complexity is $O(n^2)$, where $n$ is the size of the chessboard. The space complexity is $O(1)$.
7289

7390
<!-- tabs:start -->
7491

solution/0800-0899/0809.Expressive Words/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ tags:
3131
<p><strong>示例:</strong></p>
3232

3333
<pre>
34-
<strong>输入:</strong>
34+
<strong>输入:</strong>
3535
s = "heeellooo"
3636
words = ["hello", "hi", "helo"]
3737
<strong>输出:</strong>1

solution/0800-0899/0809.Expressive Words/README_EN.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ tags:
4141
<pre>
4242
<strong>Input:</strong> s = &quot;heeellooo&quot;, words = [&quot;hello&quot;, &quot;hi&quot;, &quot;helo&quot;]
4343
<strong>Output:</strong> 1
44-
<strong>Explanation:</strong>
44+
<strong>Explanation:</strong>
4545
We can extend &quot;e&quot; and &quot;o&quot; in the word &quot;hello&quot; to get &quot;heeellooo&quot;.
4646
We can&#39;t extend &quot;helo&quot; to get &quot;heeellooo&quot; because the group &quot;ll&quot; is not size 3 or more.
4747
</pre>

solution/0800-0899/0810.Chalkboard XOR Game/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ tags:
3535
<pre>
3636
<strong>输入:</strong> nums = [1,1,2]
3737
<strong>输出:</strong> false
38-
<strong>解释:</strong>
38+
<strong>解释:</strong>
3939
Alice 有两个选择: 擦掉数字 1 或 2。
4040
如果擦掉 1, 数组变成 [1, 2]。剩余数字按位异或得到 1 XOR 2 = 3。那么 Bob 可以擦掉任意数字,因为 Alice 会成为擦掉最后一个数字的人,她总是会输。
4141
如果 Alice 擦掉 2,那么数组变成[1, 1]。剩余数字按位异或得到 1 XOR 1 = 0。Alice 仍然会输掉游戏。

solution/0800-0899/0810.Chalkboard XOR Game/README_EN.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ tags:
3434
<pre>
3535
<strong>Input:</strong> nums = [1,1,2]
3636
<strong>Output:</strong> false
37-
<strong>Explanation:</strong>
38-
Alice has two choices: erase 1 or erase 2.
39-
If she erases 1, the nums array becomes [1, 2]. The bitwise XOR of all the elements of the chalkboard is 1 XOR 2 = 3. Now Bob can remove any element he wants, because Alice will be the one to erase the last element and she will lose.
37+
<strong>Explanation:</strong>
38+
Alice has two choices: erase 1 or erase 2.
39+
If she erases 1, the nums array becomes [1, 2]. The bitwise XOR of all the elements of the chalkboard is 1 XOR 2 = 3. Now Bob can remove any element he wants, because Alice will be the one to erase the last element and she will lose.
4040
If Alice erases 2 first, now nums become [1, 1]. The bitwise XOR of all the elements of the chalkboard is 1 XOR 1 = 0. Alice will lose.
4141
</pre>
4242

solution/0900-0999/0999.Available Captures for Rook/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ tags:
2424

2525
<p>注意:车不能穿过其它棋子,比如象和卒。这意味着如果有其它棋子挡住了路径,车就不能够吃掉棋子。</p>
2626

27-
<p>返回白车将能 <strong>吃掉</strong><strong>卒的数量</strong>。</p>
27+
<p>返回白车 <strong>攻击</strong>&nbsp;范围内 <strong>兵的数量</strong>。</p>
2828

2929
<p>&nbsp;</p>
3030

solution/1000-1099/1004.Max Consecutive Ones III/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ tags:
2121

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

24-
<p>给定一个二进制数组&nbsp;<code>nums</code>&nbsp;和一个整数 <code>k</code>,如果可以翻转最多 <code>k</code> 个 <code>0</code> ,则返回 <em>数组中连续 <code>1</code> 的最大个数</em> 。</p>
24+
<p>给定一个二进制数组&nbsp;<code>nums</code>&nbsp;和一个整数 <code>k</code>,假设最多可以翻转 <code>k</code> 个 <code>0</code> ,则返回执行操作后 <em>数组中连续 <code>1</code> 的最大个数</em> 。</p>
2525

2626
<p>&nbsp;</p>
2727

solution/1300-1399/1385.Find the Distance Value Between Two Arrays/README.md

+8-8
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,16 @@ tags:
3333
<strong>输出:</strong>2
3434
<strong>解释:</strong>
3535
对于 arr1[0]=4 我们有:
36-
|4-10|=6 &gt; d=2
37-
|4-9|=5 &gt; d=2
38-
|4-1|=3 &gt; d=2
39-
|4-8|=4 &gt; d=2
36+
|4-10|=6 &gt; d=2
37+
|4-9|=5 &gt; d=2
38+
|4-1|=3 &gt; d=2
39+
|4-8|=4 &gt; d=2
4040
所以 arr1[0]=4 符合距离要求
4141

4242
对于 arr1[1]=5 我们有:
43-
|5-10|=5 &gt; d=2
44-
|5-9|=4 &gt; d=2
45-
|5-1|=4 &gt; d=2
43+
|5-10|=5 &gt; d=2
44+
|5-9|=4 &gt; d=2
45+
|5-1|=4 &gt; d=2
4646
|5-8|=3 &gt; d=2
4747
所以 arr1[1]=5 也符合距离要求
4848

@@ -51,7 +51,7 @@ tags:
5151
<strong>|8-9|=1 &lt;= d=2</strong>
5252
|8-1|=7 &gt; d=2
5353
<strong>|8-8|=0 &lt;= d=2</strong>
54-
存在距离小于等于 2 的情况,不符合距离要求
54+
存在距离小于等于 2 的情况,不符合距离要求
5555

5656
故而只有 arr1[0]=4 和 arr1[1]=5 两个符合距离要求,距离值为 2</pre>
5757

solution/1300-1399/1385.Find the Distance Value Between Two Arrays/README_EN.md

+10-10
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,16 @@ tags:
3131
<pre>
3232
<strong>Input:</strong> arr1 = [4,5,8], arr2 = [10,9,1,8], d = 2
3333
<strong>Output:</strong> 2
34-
<strong>Explanation:</strong>
35-
For arr1[0]=4 we have:
36-
|4-10|=6 &gt; d=2
37-
|4-9|=5 &gt; d=2
38-
|4-1|=3 &gt; d=2
39-
|4-8|=4 &gt; d=2
40-
For arr1[1]=5 we have:
41-
|5-10|=5 &gt; d=2
42-
|5-9|=4 &gt; d=2
43-
|5-1|=4 &gt; d=2
34+
<strong>Explanation:</strong>
35+
For arr1[0]=4 we have:
36+
|4-10|=6 &gt; d=2
37+
|4-9|=5 &gt; d=2
38+
|4-1|=3 &gt; d=2
39+
|4-8|=4 &gt; d=2
40+
For arr1[1]=5 we have:
41+
|5-10|=5 &gt; d=2
42+
|5-9|=4 &gt; d=2
43+
|5-1|=4 &gt; d=2
4444
|5-8|=3 &gt; d=2
4545
For arr1[2]=8 we have:
4646
<strong>|8-10|=2 &lt;= d=2</strong>

solution/2000-2099/2056.Number of Valid Move Combinations On Chessboard/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@ tags:
2323

2424
<p>有一个&nbsp;<code>8 x 8</code>&nbsp;的棋盘,它包含&nbsp;<code>n</code>&nbsp;个棋子(棋子包括车,后和象三种)。给你一个长度为 <code>n</code>&nbsp;的字符串数组&nbsp;<code>pieces</code>&nbsp;,其中&nbsp;<code>pieces[i]</code>&nbsp;表示第 <code>i</code>&nbsp;个棋子的类型(车,后或象)。除此以外,还给你一个长度为 <code>n</code>&nbsp;的二维整数数组&nbsp;<code>positions</code>&nbsp;,其中 <code>positions[i] = [r<sub>i</sub>, c<sub>i</sub>]</code>&nbsp;表示第 <code>i</code>&nbsp;个棋子现在在棋盘上的位置为&nbsp;<code>(r<sub>i</sub>, c<sub>i</sub>)</code>&nbsp;,棋盘下标从 <strong>1</strong>&nbsp;开始。</p>
2525

26-
<p>棋盘上每个棋子都可以移动 <b>至多一次</b>&nbsp;每个棋子的移动中,首先选择移动的 <strong>方向</strong>&nbsp;,然后选择 <strong>移动的步数</strong>&nbsp;,同时你要确保移动过程中棋子不能移到棋盘以外的地方。棋子需按照以下规则移动:</p>
26+
<p>每个棋子的移动中,首先选择移动的 <strong>方向</strong>&nbsp;,然后选择 <strong>移动的步数</strong>&nbsp;,同时你要确保移动过程中棋子不能移到棋盘以外的地方。棋子需按照以下规则移动:</p>
2727

2828
<ul>
2929
<li>车可以 <strong>水平或者竖直</strong>&nbsp;从&nbsp;<code>(r, c)</code>&nbsp;沿着方向&nbsp;<code>(r+1, c)</code>,<code>(r-1, c)</code>,<code>(r, c+1)</code>&nbsp;或者&nbsp;<code>(r, c-1)</code>&nbsp;移动。</li>
3030
<li>后可以 <strong>水平竖直或者斜对角</strong>&nbsp;从&nbsp;<code>(r, c)</code> 沿着方向&nbsp;<code>(r+1, c)</code>,<code>(r-1, c)</code>,<code>(r, c+1)</code>,<code>(r, c-1)</code>,<code>(r+1, c+1)</code>,<code>(r+1, c-1)</code>,<code>(r-1, c+1)</code>,<code>(r-1, c-1)</code>&nbsp;移动。</li>
3131
<li>象可以 <strong>斜对角</strong>&nbsp;从&nbsp;<code>(r, c)</code>&nbsp;沿着方向&nbsp;<code>(r+1, c+1)</code>,<code>(r+1, c-1)</code>,<code>(r-1, c+1)</code>,<code>(r-1, c-1)</code>&nbsp;移动。</li>
3232
</ul>
3333

34-
<p><strong>移动组合</strong>&nbsp;包含所有棋子的 <strong>移动</strong>&nbsp;。每一秒,每个棋子都沿着它们选择的方向往前移动 <strong>一步</strong>&nbsp;,直到它们到达目标位置。所有棋子从时刻 <code>0</code>&nbsp;开始移动。如果在某个时刻,两个或者更多棋子占据了同一个格子,那么这个移动组合 <strong>不有效</strong>&nbsp;。</p>
34+
<p>你必须同时 <strong>移动</strong> 棋盘上的每一个棋子。<strong>移动组合</strong>&nbsp;包含所有棋子的 <strong>移动</strong>&nbsp;。每一秒,每个棋子都沿着它们选择的方向往前移动 <strong>一步</strong>&nbsp;,直到它们到达目标位置。所有棋子从时刻 <code>0</code>&nbsp;开始移动。如果在某个时刻,两个或者更多棋子占据了同一个格子,那么这个移动组合 <strong>不有效</strong>&nbsp;。</p>
3535

3636
<p>请你返回 <strong>有效</strong>&nbsp;移动组合的数目。</p>
3737

solution/2000-2099/2057.Smallest Index With Equal Value/README_EN.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ tags:
2828
<pre>
2929
<strong>Input:</strong> nums = [0,1,2]
3030
<strong>Output:</strong> 0
31-
<strong>Explanation:</strong>
31+
<strong>Explanation:</strong>
3232
i=0: 0 mod 10 = 0 == nums[0].
3333
i=1: 1 mod 10 = 1 == nums[1].
3434
i=2: 2 mod 10 = 2 == nums[2].
@@ -40,7 +40,7 @@ All indices have i mod 10 == nums[i], so we return the smallest index 0.
4040
<pre>
4141
<strong>Input:</strong> nums = [4,3,2,1]
4242
<strong>Output:</strong> 2
43-
<strong>Explanation:</strong>
43+
<strong>Explanation:</strong>
4444
i=0: 0 mod 10 = 0 != nums[0].
4545
i=1: 1 mod 10 = 1 != nums[1].
4646
i=2: 2 mod 10 = 2 == nums[2].

solution/2200-2299/2227.Encrypt and Decrypt Strings/README_EN.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ encrypter.decrypt(&quot;eizfeiam&quot;); // return 2.
7878
<li><code>1 &lt;= dictionary[i].length &lt;= 100</code></li>
7979
<li>All <code>keys[i]</code> and <code>dictionary[i]</code> are <strong>unique</strong>.</li>
8080
<li><code>1 &lt;= word1.length &lt;= 2000</code></li>
81-
<li><code>1 &lt;= word2.length &lt;= 200</code></li>
81+
<li><code>2 &lt;= word2.length &lt;= 200</code></li>
8282
<li>All <code>word1[i]</code> appear in <code>keys</code>.</li>
8383
<li><code>word2.length</code> is even.</li>
8484
<li><code>keys</code>, <code>values[i]</code>, <code>dictionary[i]</code>, <code>word1</code>, and <code>word2</code> only contain lowercase English letters.</li>

solution/3000-3099/3001.Minimum Moves to Capture The Queen/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ edit_url: https://github.com/doocs/leetcode/edit/main/solution/3000-3099/3001.Mi
55
rating: 1796
66
source: 第 379 场周赛 Q2
77
tags:
8-
- 数组
8+
- 数学
99
- 枚举
1010
---
1111

solution/3000-3099/3001.Minimum Moves to Capture The Queen/README_EN.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ edit_url: https://github.com/doocs/leetcode/edit/main/solution/3000-3099/3001.Mi
55
rating: 1796
66
source: Weekly Contest 379 Q2
77
tags:
8-
- Array
8+
- Math
99
- Enumeration
1010
---
1111

@@ -55,7 +55,7 @@ It is impossible to capture the black queen in less than two moves since it is n
5555
<pre>
5656
<strong>Input:</strong> a = 5, b = 3, c = 3, d = 4, e = 5, f = 2
5757
<strong>Output:</strong> 1
58-
<strong>Explanation:</strong> We can capture the black queen in a single move by doing one of the following:
58+
<strong>Explanation:</strong> We can capture the black queen in a single move by doing one of the following:
5959
- Move the white rook to (5, 2).
6060
- Move the white bishop to (5, 2).
6161
</pre>

solution/3300-3399/3370.Smallest Number With All Set Bits/README_EN.md

+1-3
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,7 @@ tags:
1919

2020
<p>You are given a <em>positive</em> number <code>n</code>.</p>
2121

22-
<p>Return the <strong>smallest</strong> number <code>x</code> <strong>greater than</strong> or <strong>equal to</strong> <code>n</code>, such that the binary representation of <code>x</code> contains only <strong>set</strong> bits.</p>
23-
24-
<p>A <strong>set</strong> bit refers to a bit in the binary representation of a number that has a value of <code>1</code>.</p>
22+
<p>Return the <strong>smallest</strong> number <code>x</code> <strong>greater than</strong> or <strong>equal to</strong> <code>n</code>, such that the binary representation of <code>x</code> contains only <span data-keyword="set-bit">set bits</span></p>
2523

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

solution/3300-3399/3371.Identify the Largest Outlier in an Array/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ tags:
1919

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

22-
<p>给你一个整数数组 <code>nums</code>。该数组包含 <code>n</code> 个元素,其中&nbsp;<strong>恰好&nbsp;</strong>有 <code>n - 2</code> 个元素是&nbsp;<strong>特殊数字&nbsp;</strong>。剩下的&nbsp;<strong>两个&nbsp;</strong>元素中,一个是这些&nbsp;<strong>特殊数字&nbsp;</strong>的 <strong>和</strong> ,另一个是&nbsp;<strong>异常值&nbsp;</strong>。</p>
22+
<p>给你一个整数数组 <code>nums</code>。该数组包含 <code>n</code> 个元素,其中&nbsp;<strong>恰好&nbsp;</strong>有 <code>n - 2</code> 个元素是&nbsp;<strong>特殊数字&nbsp;</strong>。剩下的&nbsp;<strong>两个&nbsp;</strong>元素中,一个是所有&nbsp;<strong>特殊数字&nbsp;</strong>的 <strong>和</strong> ,另一个是&nbsp;<strong>异常值&nbsp;</strong>。</p>
2323

24-
<p><strong>异常值</strong> 的定义是:既不是原始特殊数字之一,也不是表示这些数字元素和的数字。</p>
24+
<p><strong>异常值</strong> 的定义是:既不是原始特殊数字之一,也不是所有特殊数字的和。</p>
2525

2626
<p><strong>注意</strong>,特殊数字、和 以及 异常值 的下标必须&nbsp;<strong>不同&nbsp;</strong>,但可以共享&nbsp;<strong>相同</strong> 的值。</p>
2727

0 commit comments

Comments
 (0)