Python O(n) solution


  • 0
    class Solution(object):
        def isStrobogrammatic(self, num):
            dic = {"6": "9", "8": "8", "1": "1", "9": "6", "0": "0"}
            p1, p2 = 0, len(num)-1
            while p1 <= p2:
                if num[p1] not in dic or num[p2] not in dic:
                    return False
                if dic[num[p1]] != num[p2]:
                    return False
                p1 += 1
                p2 -= 1
            return True
    

Log in to reply
 

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