美文网首页Leetcode
Leetcode 1812. Determine Color o

Leetcode 1812. Determine Color o

作者: SnailTyan | 来源:发表于2021-08-10 10:42 被阅读0次

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

1. Description

Determine Color of a Chessboard Square

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

  1. https://leetcode.com/problems/determine-color-of-a-chessboard-square/

相关文章

网友评论

    本文标题:Leetcode 1812. Determine Color o

    本文链接:https://www.haomeiwen.com/subject/xmmjmltx.html