Skip to content

Commit 2ee3b36

Browse files
authored
feat: add weekly contest 427 and biweekly contest 145 (doocs#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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 18 additions & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 3 additions & 3 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

0 commit comments

Comments
 (0)