# 转字符串
def is_palindrome(n):
m = str(n)
return m == reduce(lambda x,y:y+x,m)
# 转字符串,也可以只比较一半长度
def is_palindrome(n):
m = str(n)
index = 0
while index < len(m) // 2:
if m[index] != m[-(index + 1)]:
return False
index += 1
return True
# 直接操作整数
def is_palindrome(num):
if num<0 or (num!=0 and num%10 == 0):
return False
temp = 0
while temp<num:
temp = temp*10+num%10
num//=10
return temp == num or temp//10 == num
浪过扬帆