Skip to content

feat: add solutions to lc problems: No.3383,3384 #3850

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ tags:

观察棋盘我们发现,颜色相同的两个格子 $(x_1, y_1)$ 和 $(x_2, y_2)$ 满足 $x_1 + y_1$ 和 $x_2 + y_2$ 均为奇数或偶数。

因此,我们可以根据 `coordinates` 获取对应的坐标 $(x, y)$,如果 $x + y$ 为奇数,则格子为白色,返回 `true`,否则返回 `false`
因此,我们可以根据 $\textit{coordinates}$ 获取对应的坐标 $(x, y)$,如果 $x + y$ 为奇数,则格子为白色,返回 $\textit{true}$,否则返回 $\textit{false}$

时间复杂度 $O(1)$,空间复杂度 $O(1)$。

Expand Down Expand Up @@ -142,9 +142,7 @@ impl Solution {
* @return {boolean}
*/
var squareIsWhite = function (coordinates) {
const x = coordinates.charAt(0).charCodeAt();
const y = coordinates.charAt(1).charCodeAt();
return (x + y) % 2 == 1;
return (coordinates[0].charCodeAt() + coordinates[1].charCodeAt()) % 2 == 1;
};
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,11 @@ tags:

<!-- solution:start -->

### Solution 1: Find the Pattern
### Solution 1: Pattern Recognition

By observing the chessboard, we find that two squares $(x_1, y_1)$ and $(x_2, y_2)$ with the same color satisfy that both $x_1 + y_1$ and $x_2 + y_2$ are either odd or even.
Observing the chessboard, we find that two squares $(x_1, y_1)$ and $(x_2, y_2)$ with the same color satisfy that both $x_1 + y_1$ and $x_2 + y_2$ are either odd or even.

Therefore, we can get the corresponding coordinates $(x, y)$ from `coordinates`. If $x + y$ is odd, then the square is white, return `true`, otherwise return `false`.
Therefore, we can get the corresponding coordinates $(x, y)$ from $\textit{coordinates}$. If $x + y$ is odd, the square is white, and we return $\textit{true}$; otherwise, we return $\textit{false}$.

The time complexity is $O(1)$, and the space complexity is $O(1)$.

Expand Down Expand Up @@ -140,9 +140,7 @@ impl Solution {
* @return {boolean}
*/
var squareIsWhite = function (coordinates) {
const x = coordinates.charAt(0).charCodeAt();
const y = coordinates.charAt(1).charCodeAt();
return (x + y) % 2 == 1;
return (coordinates[0].charCodeAt() + coordinates[1].charCodeAt()) % 2 == 1;
};
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,5 @@
* @return {boolean}
*/
var squareIsWhite = function (coordinates) {
const x = coordinates.charAt(0).charCodeAt();
const y = coordinates.charAt(1).charCodeAt();
return (x + y) % 2 == 1;
return (coordinates[0].charCodeAt() + coordinates[1].charCodeAt()) % 2 == 1;
};
2 changes: 1 addition & 1 deletion solution/1800-1899/1891.Cutting Ribbons/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ tags:

</ul>

<p>Your task is to determine the <strong>maximum</strong> length of ribbon, <code>x</code>, that allows you to cut <em>exactly</em> <code>k</code> ribbons, each of length <code>x</code>. You can discard any leftover ribbon from the cuts. If it is <strong>impossible</strong> to cut <code>k</code> ribbons of the same length, return 0.</p>
<p>Your task is to determine the <strong>maximum</strong> length of ribbon, <code>x</code>, that allows you to cut <em>at least</em> <code>k</code> ribbons, each of length <code>x</code>. You can discard any leftover ribbon from the cuts. If it is <strong>impossible</strong> to cut <code>k</code> ribbons of the same length, return 0.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ tags:
<strong>Input:</strong> banned = [4,3,5,6], n = 7, maxSum = 18
<strong>Output:</strong> 3
<strong>Explanation:</strong> You can choose the integers 1, 2, and 7.
All these integers are in the range [1, 7], all do not appear in banned, and their sum is 18, which does not exceed maxSum.
All these integers are in the range [1, 7], all do not appear in banned, and their sum is 10, which does not exceed maxSum.
</pre>

<p>&nbsp;</p>
Expand Down
Loading
Loading