Python solution, best case beats 89%


  • 0
    S
        strobes = { 0:0,1:1,6:9,8:8,9:6 }
        
        # in order to determine a strobe pair, the characters must be swapped with their respective strobe pair (i.e. 6 and 9) and replaced with the mapped value of itself
        
        strobe_list = list(num)
        
        # reverse of the string
        
        strobe_list = strobe_list[::-1]
        
        # replace all of its values with it's respective mapping
        
        res = ""
        for elem in strobe_list:
            if strobes.get(int(elem)) is None:
                continue
            else:
                res += str(strobes.get(int(elem)))
    
        if res == num:
            return True
        
        return False

Log in to reply
 

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