一、題目
Palindrome Number
二、解題
判斷一個(gè)數(shù)字是否是回文串。
左邊:使用字符串來(lái)操作
右邊:使用數(shù)字來(lái)操作
感覺(jué)這題怎么樣都可以實(shí)現(xiàn)。
三、嘗試與結(jié)果
class Solution(object):
def isPalindrome(self, x):
if x < 0 :
return False
i = 0
while i < len(str(x))/2:
left = str(x)[i]
right = x/(10 ** i) % 10
if int(left) != right:
return False
i = i + 1
return True
結(jié)果:AC