Strobogrammatic Number

哈希表映射一下就好

class Solution(object):
    def isStrobogrammatic(self, num):
        """
        :type num: str
        :rtype: bool
        """
        mirror = {'1':'1', '0':'0', '6':'9', '9':'6', '8':'8'}
        result = ''

        for char in num:
            if char not in mirror:
                return False
            result = mirror[char] + result
        return result == num

results matching ""

    No results matching ""