concise code using two pointers


  • 0
    class Solution(object):
        def isStrobogrammatic(self, num):
            """
            :type num: str
            :rtype: bool
            """
            i, j = 0, len(num) - 1
            while i < j:
                s = num[i] + num[j]
                if s in ['69', '96', '88', '11', '00']:
                    i += 1
                    j -= 1
                else:
                    return False
            if i == j:
                return True if num[i] in '018' else False
            else:
                return True
    

Log in to reply
 

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