Don't understand why this is slow, 88 ms?!


  • 0
    W

    Don't understand why this is slow, 88 ms

    pairs = {"6":"9","9":"6","8":"8","1":"1","0":"0"}
    single = {"2","3","4","5","7"}
    def isStrobogrammatic(self, num):
        for i in range((len(num)+1)/2):
            if num[i] in self.single or self.pairs[num[i]]!=num[~i]:
                return False
        return True

  • 0
    W

    Still slow, 55s:

    pairs = {"6":"9","9":"6","8":"8","1":"1","0":"0"}
    single = {"2","3","4","5","7"}
    def isStrobogrammatic(self, num):
        for c in self.single:
            if num.find(c)>-1: return False
        for i in range((len(num)+1)/2):
            if self.pairs[num[i]]!=num[~i]:
                return False
        return True

Log in to reply
 

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