#思路是把123变为321,先通过除法把每一位数字确定,再通过乘法放到对应位置上,最后判断两者是否相等
def is_palindrome(n):
origin = n
length = len(str(n))
result = 0
while length > 0:
yushu = n % 10
n = n // 10
length = length - 1
result = result + yushu * (10 ** length)
return origin == result
Sign in to make a reply
11点提前睡觉
#思路是把123变为321,先通过除法把每一位数字确定,再通过乘法放到对应位置上,最后判断两者是否相等
def is_palindrome(n):
origin = n
length = len(str(n))
result = 0
while length > 0:
yushu = n % 10
n = n // 10
length = length - 1
result = result + yushu * (10 ** length)
return origin == result