File tree Expand file tree Collapse file tree 1 file changed +38
-0
lines changed Expand file tree Collapse file tree 1 file changed +38
-0
lines changed Original file line number Diff line number Diff line change 1+ ```
2+ 1812 . Determine Color of a Chessboard Square
3+
4+ You are given coordinates, a string that represents the coordinates of a square of the chessboard. Below is a chessboard for your reference.
5+
6+ Return true if the square is white, and false if the square is black.
7+
8+ The coordinate will always represent a valid chessboard square. The coordinate will always have the letter first, and the number second.
9+
10+
11+
12+ Example 1 :
13+
14+ Input: coordinates = " a1"
15+ Output: false
16+ Explanation: From the chessboard above, the square with coordinates " a1" is black, so return false .
17+
18+ Example 2 :
19+
20+ Input: coordinates = " h3"
21+ Output: true
22+ Explanation: From the chessboard above, the square with coordinates " h3" is white, so return true .
23+
24+ Example 3 :
25+
26+ Input: coordinates = " c7"
27+ Output: false
28+
29+ ```
30+ class Solution {
31+ public:
32+ bool squareIsWhite (string coordinates) {
33+ int col = coordinates[0 ]-' a' + 1 ;
34+ int row = coordinates[1 ];
35+
36+ return (col+row)%2 == 1 ;
37+ }
38+ };
You can’t perform that action at this time.
0 commit comments