-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy path1812.DetermineColorofaChessboardSquare.py
44 lines (36 loc) · 1.37 KB
/
1812.DetermineColorofaChessboardSquare.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
'''
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:
Input: coordinates = "a1"
Output: false
Explanation: From the chessboard above, the square with
coordinates "a1" is black, so return false.
Example:
Input: coordinates = "h3"
Output: true
Explanation: From the chessboard above, the square with
coordinates "h3" is white, so return true.
Example:
Input: coordinates = "c7"
Output: false
Constraints:
- coordinates.length == 2
- 'a' <= coordinates[0] <= 'h'
- '1' <= coordinates[1] <= '8'
'''
#Dfficulty: Easy
#203 / 203 test cases passed.
#Runtime: 32 ms
#Memory Usage: 14.1 MB
#Runtime: 32 ms, faster than 68.51% of Python3 online submissions for Determine Color of a Chessboard Square.
#Memory Usage: 14.1 MB, less than 71.83% of Python3 online submissions for Determine Color of a Chessboard Square.
class Solution:
def squareIsWhite(self, coordinates: str) -> bool:
return not ord(coordinates[0]) % 2 == int(coordinates[1]) % 2