Determine whether an integer is a palindrome. Do this without extra space.
class Solution
{
public:
bool isPalindrome(int x)
{
if(x < 0) return false;
if(x < 10) return true;
int y = 0;
int tmp = x;
while(x)
{
y = y*10 + x % 10;
x = x/ 10;
}
if(tmp == y) return true;
return false;
}
};

本文介绍了一种不使用额外空间来判断整数是否为回文数的方法,通过反转一半的数字并与原始数字进行比较实现。
177

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



