Determine whether an integer is a palindrome. Do this without extra space.
class Solution:
def isPalindrome(self, x):
ans = [];
if x < 0:
return False;
if x < 10:
return True;
while x > 0:
ans.append(x%10);
x = x/10;
i = 0;
j = len(ans)-1;
while i <= j:
if ans[i] == ans[j]:
i += 1;
j -= 1;
else:
break;
if i >= j:
return True;
else:
return False;
本文介绍了一种不使用额外空间来判断整数是否为回文数的方法,通过反转一半的数字并与原始数字进行比较实现。
677

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



