文章作者:Tyan
博客:noahsnail.com | CSDN | 简书
1. Description
Determine Color of a Chessboard Square2. 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]
网友评论