LeetCode 1812. Determine Color of a Chessboard Square
Last updated
Last updated
Input: coordinates = "a1"
Output: false
Explanation: From the chessboard above, the square with coordinates "a1" is black, so return false.Input: coordinates = "h3"
Output: true
Explanation: From the chessboard above, the square with coordinates "h3" is white, so return true.Input: coordinates = "c7"
Output: falseclass Solution {
public:
bool squareIsWhite(string coordinates) {
return ((coordinates[0] - 'a') % 2) == ((coordinates[1] - '0') % 2);
}
};