The title

Coordinates are given to you, which is a string representing the coordinates of a grid on a chess board. Below is a schematic diagram of a chess board.

Return true if the color of the given grid is white, false if black.

The given coordinates must represent an existing grid on a chess board. The first character of a coordinate is a letter and the second character is a number.

Example 1: Input: Coordinates = "a1" Output: false Explanation: As shown on the checkerboard above, the grid of "a1" coordinates is black, so return false. Example 2: Enter: Coordinates = "h3" Output: true Explanation: As shown on the checkerboard above, the grid of "h3" coordinates is white, so return true. Example 3: Enter: coordinates = "c7" output: falseCopy the code

Tip:

coordinates.length == 2 ‘a’ <= coordinates[0] <= ‘h’ ‘1’ <= coordinates[1] <= ‘8’

Their thinking

class Solution: def squareIsWhite(self, coordinates: str) -> bool: Coordinates [0])-97+1 two = int(coordinates[1]) return (one+two)%2 == 1 if __name__ == '__main__': coordinates = "a1" coordinates = "h3" ret = Solution().squareIsWhite(coordinates) print(ret)Copy the code