[LeetCode]#1812. Determine Color of a Chessboard Square

Environment: Python 3.8

Key technique: if, ord, ASCII
You are given coordinates, a string that represents the coordinates of a square of the chessboard. Below is a chessboard for your reference.

Return true if the square is white, and false if the square is black.

The coordinate will always represent a valid chessboard square. The coordinate will always have the letter first, and the number second.

Example 1:

Input: coordinates = "a1"
Output: false
Explanation: From the chessboard above, the square with coordinates "a1" is black, so return false.

Analysis:

  1. Convert ‘a’ and ‘1’ to ASCII.

Solution:

class Solution:
def squareIsWhite(self, coordinates):
test=coordinates[0]
number=coordinates[1]
if ((ord(test)+ord(number)) % 2 !=0):
return True
else:
return False

Submissions: