leecode刷题:5705. 判断国际象棋棋盘中一个格子的颜色

in hive-180932 •  3 years ago  (edited)

image.png

参加周赛,时间有限,没啥想法,写了很奇怪的答案。

class Solution:
    def squareIsWhite(self, coordinates: str) -> bool:
        list1="01010101"
        list2="10101010"
        if coordinates[0] in "aceg":
            flag=list1[int(coordinates[1])-1]
        else:
            flag = list2[int(coordinates[1]) - 1]
        if flag == "0":
            return False
        else:
            return True

怎么这都不是一个正经的答案,但是能过。

后来仔细想想,只要把a1拆开,判断a+1是不是偶数就能知道答案了。一行解决

class Solution:
    def squareIsWhite(self, coordinates: str) -> bool:
        return True if ((ord(coordinates[0]))+int(coordinates[1])) % 2 else False
Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!
Sort Order:  

Hello there,

what has happened to follow.steems.top? The page is down, and I really liked it and loved to use it!! :) Please help :) Would happily send you some Steem as a thank you as well if you made it work once again!