Leetcode 1812. Determine Color of a Chessboard Square

2021-07-23 16:21:42 浏览数 (1)

1. Description

2. Solution

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

  • Version 1
代码语言:javascript复制
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/

0 人点赞