beats 93% Python solution


  • 0
    H
    class Solution(object):
        def isStrobogrammatic(self, num):
            """
            :type num: str
            :rtype: bool
            """
    
            left, right = 0, len(num) - 1
            while left < right:
                if num[left] == num[right]:
                    if num[left] not in '018':
                        return False
                elif num[left] < num[right]:
                    if num[left] != '6' or num[right] != '9':
                        return False
                else:
                    if num[left] != '9' or num[right] != '6':
                        return False
                left += 1
                right -= 1
                
            if left == right:
                if num[left] not in '018':
                    return False
            return True
    

Log in to reply
 

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