Python dictionary solution


  • 0
    P
    def isStrobogrammatic(self, num):
    
        d = {'0':'0', '1':'1', '8':'8', '6':'9', '9':'6'}
        
        if len(num) == 1 and num not in d: return False
            
        mirror = str()
        
        for ch in num[::-1]:
            mirror += d.get(ch, str())
        
        return mirror == num
    

Log in to reply
 

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