Leetcode 1812. Determine Color of a Chessboard Square
Posted SnailTyan
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Leetcode 1812. Determine Color of a Chessboard Square相关的知识,希望对你有一定的参考价值。
文章作者:Tyan
博客:noahsnail.com | CSDN | 简书
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
以上是关于Leetcode 1812. Determine Color of a Chessboard Square的主要内容,如果未能解决你的问题,请参考以下文章
LeetCode 1812. 判断国际象棋棋盘中一个格子的颜色
[LeetCode] 1886. Determine Whether Matrix Can Be Obtained By Rotation
LeetCode1812. 判断国际象棋棋盘中一个格子的颜色(C++)