美文网首页
leetcode 788. 旋转数字

leetcode 788. 旋转数字

作者: fanchuang | 来源:发表于2020-03-11 05:08 被阅读0次

很拙劣的写法。

class Solution:
    def rotatedDigits(self, N: int) -> int:
        # 除了这些以外其他的数字旋转以后都不再是有效的数字。
        # 23 53     24  54  都不算

        d = {"0": 0, "1": 1, "2": 5, "5": 2, "6": 9, "8": 8, "9": 6}

        ret = 0
        for i in range(1, N+1):
            s = str(i)
            if all(j in d for j in s):
                t = list(s).copy()
                rot = ""
                for j in s:
                    if str(j) in d:
                        j = d[str(j)]
                        rot += str(j)
                    
                if rot != ''.join(t):
                    # print(''.join(t), rot)
                    ret += 1
        return ret 

相关文章

网友评论

      本文标题:leetcode 788. 旋转数字

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