Skip to content

Commit 9a440d4

Browse files
committed
feat: add solutions to lc problem: No.1812
No.1812.Determine Color of a Chessboard Square
1 parent 2a835ee commit 9a440d4

File tree

5 files changed

+67
-1
lines changed

5 files changed

+67
-1
lines changed

solution/1800-1899/1812.Determine Color of a Chessboard Square/README.md

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ class Solution:
8080
```java
8181
class Solution {
8282
public boolean squareIsWhite(String coordinates) {
83-
return (coordinates.charAt(0) + coordinates.charAt(1)) % 2 == 1;
83+
return (coordinates.charAt(0) + coordinates.charAt(1)) % 2 == 1;
8484
}
8585
}
8686
```
@@ -118,6 +118,33 @@ var squareIsWhite = function (coordinates) {
118118
};
119119
```
120120

121+
### **TypeScript**
122+
123+
```ts
124+
function squareIsWhite(coordinates: string): boolean {
125+
return ((coordinates.charCodeAt(0) + coordinates.charCodeAt(1)) & 1) === 1;
126+
}
127+
```
128+
129+
### **Rust**
130+
131+
```rust
132+
impl Solution {
133+
pub fn square_is_white(coordinates: String) -> bool {
134+
let s = coordinates.as_bytes();
135+
s[0] + s[1] & 1 == 1
136+
}
137+
}
138+
```
139+
140+
### **C**
141+
142+
```c
143+
bool squareIsWhite(char *coordinates) {
144+
return (coordinates[0] + coordinates[1]) & 1;
145+
}
146+
```
147+
121148
### **...**
122149
123150
```

solution/1800-1899/1812.Determine Color of a Chessboard Square/README_EN.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,33 @@ var squareIsWhite = function (coordinates) {
100100
};
101101
```
102102

103+
### **TypeScript**
104+
105+
```ts
106+
function squareIsWhite(coordinates: string): boolean {
107+
return ((coordinates.charCodeAt(0) + coordinates.charCodeAt(1)) & 1) === 1;
108+
}
109+
```
110+
111+
### **Rust**
112+
113+
```rust
114+
impl Solution {
115+
pub fn square_is_white(coordinates: String) -> bool {
116+
let s = coordinates.as_bytes();
117+
s[0] + s[1] & 1 == 1
118+
}
119+
}
120+
```
121+
122+
### **C**
123+
124+
```c
125+
bool squareIsWhite(char *coordinates) {
126+
return (coordinates[0] + coordinates[1]) & 1;
127+
}
128+
```
129+
103130
### **...**
104131
105132
```
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
bool squareIsWhite(char *coordinates) {
2+
return (coordinates[0] + coordinates[1]) & 1;
3+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
impl Solution {
2+
pub fn square_is_white(coordinates: String) -> bool {
3+
let s = coordinates.as_bytes();
4+
s[0] + s[1] & 1 == 1
5+
}
6+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
function squareIsWhite(coordinates: string): boolean {
2+
return ((coordinates.charCodeAt(0) + coordinates.charCodeAt(1)) & 1) === 1;
3+
}

0 commit comments

Comments
 (0)