Python


  • 0
    B
    class Solution(object):
        def isStrobogrammatic(self, num):
            """
            :type num: str
            :rtype: bool
            """
            hashmap = {6:9, 9:6, 1:1, 0:0, 8:8}
            if len(num) < 1: return True
            left = 0
            right = len(num)-1
            while(left <= right):
                    if int(num[left]) not in hashmap or int(num[right]) not in hashmap:
                            return False
                    if int(num[left]) != hashmap[int(num[right])]:
                            return False
                    left  += 1
                    right -= 1
            return True
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.