You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<li>All the tweets have <strong>unique</strong> IDs.</li>
62
62
<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>
63
64
</ul>
64
65
65
66
<!-- description:end -->
Collapse file: solution/0700-0799/0782.Transform to Chessboard/README.md
Copy file name to clipboardExpand all lines: solution/0700-0799/0782.Transform to Chessboard/README_EN.md
+18-1Lines changed: 18 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -68,7 +68,24 @@ The second move swaps the second and third row.
68
68
69
69
<!-- solution:start -->
70
70
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)$.
Copy file name to clipboardExpand all lines: solution/0800-0899/0810.Chalkboard XOR Game/README_EN.md
+3-3Lines changed: 3 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -34,9 +34,9 @@ tags:
34
34
<pre>
35
35
<strong>Input:</strong> nums = [1,1,2]
36
36
<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.
40
40
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.
41
41
</pre>
42
42
Collapse file: solution/0900-0999/0999.Available Captures for Rook/README.md
0 commit comments