Determine whether an integer is a palindrome. Do this without extra space.
回文数,这里将其转换成string,就很容易处理了。
class Solution(object):
def isPalindrome(self, x):
"""
:type x: int
:rtype: bool
"""
if x<0:
return False
else:
x = str(x)
for i in range(len(x)/2):
if x[i] != x[len(x)-1 - i]:
return False
return True
本文介绍了一种不使用额外空间判断整数是否为回文数的方法。通过将整数转换为字符串,可以轻松地实现从头到尾及从尾到头的双向比较,从而确定该数是否为回文数。
174

被折叠的 条评论
为什么被折叠?



