题目
Determine whether an integer is a palindrome. Do this without extra space.
负数肯定不是。
要求不能用额外的空间,直接取高位和低位比较。
代码:
class Solution {
public:
bool isPalindrome(int x) {
if(x<0)
return false;
int radix=1;
while(x/radix>=10)
radix*=10;
while(x>0)
{
if(x/radix!=x%10)
return false;
x=x%radix/10;
radix/=100;
}
return true;
}
};