Skip to content

1812. Determine Color of a Chessboard Square 👍

  • Time: $O(1)$
  • Space: $O(1)$
1
2
3
4
5
6
7
8
class Solution {
 public:
  bool squareIsWhite(string coordinates) {
    const char letter = coordinates[0];
    const char digit = coordinates[1];
    return letter % 2 != digit % 2;
  }
};
1
2
3
4
5
6
7
class Solution {
  public boolean squareIsWhite(String coordinates) {
    final char letter = coordinates.charAt(0);
    final char digit = coordinates.charAt(1);
    return letter % 2 != digit % 2;
  }
}
1
2
3
4
class Solution:
  def squareIsWhite(self, coordinates: str) -> bool:
    letter, digit = coordinates
    return ord(letter) % 2 != int(digit) % 2