判斷一個整數(shù)是否是回文數(shù)。回文數(shù)是指正序(從左向右)和倒序(從右向左)讀都是一樣的整數(shù)。
class Solution(object):
def isPalindrome(self, x):
new_num = 0
a = abs(x)
while a != 0:
temp = a%10
new_num = new_num*10 + temp
# 注意python中的除法和地板除
a = a//10
# 輸入等于輸出時成立
if x >= 0 and x == new_num:
return True
else:
return False