Determine whether an integer is a palindrome. Do this without extra space.
考虑到回文的特点,根据给定数字获得与给定数字低位高位反序的数字。如果是回文数,则两数想等;否则不等。(即使反序数字溢出,也可的到正确结果)
bool isPalindrome(int x) { //C++
int test = 0;
int tmp = x;
while(tmp>0 )
{
test = test*10+tmp%10;
tmp = tmp/10;
}
return (test==x);
}原文地址:http://blog.csdn.net/chenlei0630/article/details/41727807