Leetcode 1812. Determine Color of a Chessboard Square

文章作者:Tyan
博客:noahsnail.com  |  CSDN  |  简书

1. Description

Determine Color of a Chessboard Square

2. Solution

解析:Version 1,构建字典,返回对应的结果即可。

  • Version 1
1
2
3
4
5
6
7
8
9
10
11
12
13
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

  1. https://leetcode.com/problems/determine-color-of-a-chessboard-square/
如果有收获,可以请我喝杯咖啡!