Strobogrammatic Number
class Solution(object):
def isStrobogrammatic(self, num):
"""
:type num: str
:rtype: bool
"""
left = 0
right = len(num)-1
dic = {'9':'6', '6':'9', '1':'1', '8':'8', '0':'0'}
while left <= right:
# 如果字母不存在映射或映射不对,则返回假
if num[left] not in dic or num[right] not in dic or dic[num[right]] != num[left]:
return False
left += 1
right -= 1
return TrueLast updated