Skip to content

Commit 9b91b7c

Browse files
committed
commit solution S1812
1 parent cf625cc commit 9b91b7c

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ LeetCode
55

66
| # | Title | | Difficulty|
77
|---| ----- | -------- | -------- |
8+
[1812][ Determine Color of a Chessboard Square](https://leetcode-cn.com/problems/determine-color-of-a-chessboard-square/) | [Java](https://github.com/xiao2shiqi/leetcode/blob/master/src/main/java/S1812.java)
89
|1550|[Three Consecutive Odds](https://leetcode-cn.com/problems/three-consecutive-odds/) | [Go](https://github.com/xiao2shiqi/leetcode/blob/master/go/1550.go) | Easy
910
|992|[Sort Array By Parity II](https://leetcode-cn.com/problems/sort-array-by-parity-ii/) | [Go](https://github.com/xiao2shiqi/leetcode/blob/master/go/992.go) | Easy
1011
|977|[Squares of a Sorted Array](https://leetcode-cn.com/problems/squares-of-a-sorted-array/) | [Go](https://github.com/xiao2shiqi/leetcode/blob/master/go/977.go) | Easy

src/main/java/S1812.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* LC#1812:判断国际象棋棋盘中一个格子的颜色
3+
* Link:https://leetcode-cn.com/problems/determine-color-of-a-chessboard-square/
4+
* 思路1:将 8x8 按照奇偶数放入 Hash 中,然后根据 coordinates 获取结果值
5+
* 思路2:根据规律可以预判出横轴坐标加纵轴坐标,直接返回结果即可
6+
* @author Phoenix on 2021/7/3.
7+
*/
8+
public class S1812 {
9+
10+
public boolean squareIsWhite(String coordinates) {
11+
int firstIndex = coordinates.charAt(0);
12+
int lastIndex = coordinates.charAt(1);
13+
return (firstIndex % 2) + (lastIndex % 2) == 1;
14+
}
15+
16+
public static void main(String[] args) {
17+
boolean squareIsWhite = new S1812().squareIsWhite("a3");
18+
System.out.println(">>>");
19+
System.out.println(squareIsWhite);
20+
21+
}
22+
}

0 commit comments

Comments
 (0)