1. Description
2. Solution
**解析:**Version 1,构建字典,返回对应的结果即可。
- Version 1
class Solution:
def squareIsWhite(self, coordinates: str) -> bool:
rows = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h']
columns = list(range(1, 9))
flag = True
mapping = {}
for row in rows:
flag = not flag
for col in columns:
index = row str(col)
mapping[index] = flag
flag = not flag
return mapping[coordinates]
Reference
- https://leetcode.com/problems/determine-color-of-a-chessboard-square/