leetcode246.中心对称数

1,278 阅读1分钟

246.中心对称数

中心对称数是指一个数字在旋转了 180 度之后看起来依旧相同的数字(或者上下颠倒地看)。

请写一个函数来判断该数字是否是中心对称数,其输入将会以一个字符串的形式来表达数字。

输入: "69" 输出: true 输入: "88" 输出: true 输入: "962" 输出: false

class Solution(object):
    def isStrobogrammatic(self, num: str) -> bool:
        start, end, legal = 0, len(num) - 1, ["00", "11", "88", "69"]
        while start <= end:
            if "".join(sorted(num[start] + num[end])) not in legal:
                return False
            start += 1
            end -= 1
        return True