Determine whether an integer is a palindrome. Do this without extra space.
暴力的时候,注意奇数偶数。
1 class Solution: 2 def isPalindrome(self, x): 3 """ 4 :type x: int 5 :rtype: bool 6 """ 7 x =str(x) 8 9 if(len(x)%2!=0):#数 10 for i in range(int(len(x)/2)+1): 11 if(x[i]!=x[len(x)-i-1]): 12 return False 13 else: 14 for i in range(int(len(x)/2)+1): 15 if(x[i]!=x[len(x)-i-1]): 16 return False 17 return True 18 19
原文地址:https://www.cnblogs.com/zle1992/p/8452811.html
时间: 2024-10-11 12:55:35