回文数Python实现
class Solution(object):
def isPalindrome(self, x):
"""
:type x: int
:rtype: bool
"""
temp = str(x)[::-1]
if(temp == str(x)):
return True
else:
return False
复杂低幼版:
# python
class Solution(object):
def isPalindrome(self, x):
"""
:type x: int
:rtype: bool
"""
str1 = str(x)
if str1[0] == '-':
print('false')
for i in range(int(len(str1) / 2) + 1):
if i == len(str1) - i - 1 or (str1[i] == str1[len(str1) - i - 1] and (i + 1) == (len(str1) - i - 1)):
print('true')
if str1[i] != str1[len(str1) - i - 1]:
print('false')
break