Question
A strobogrammatic number is a number that looks the same when rotated 180 degrees (looked at upside down).
Write a function to determine if a number is strobogrammatic. The number is represented as a string.
For example, the numbers “69”, “88”, and “818” are all strobogrammatic.
Hide Tags Hash Table Math
Hide Similar Problems (M) Strobogrammatic Number II (H) Strobogrammatic Number III
My Solution
“`python
class Solution(object):
def isStrobogrammatic(self, num):
“””
:type num: str
:rtype: bool
“”“
if num==None or num=='':
return False
start, end = 0, len(num)-1
while start<=end:
if not self.check(num, start, end):
return False
start += 1
end -= 1
return True
def check(self, num, i, j):
if i==j:
if num[i] in ['0','1','8']:
return True
else:
if num[i]==num[j] and num[i] in ['0','1','8']:
return True
if (num[i],num[j])==('6','9') or (num[i],num[j])==('9','6'):
return True
return False
“`