题目:
Determine whether an integer is a palindrome. Do this without extra space.
难度
easy
思路:每一个提取最高位和最低位进行比较即可
代码如下
using namespace std;
class Solution {
public:
bool isPalindrome(int x) {
if(x<0)
return false;
if(x<10)
return true;
int d=1;//divisor
while(x/d>=10)
d*=10;//calculate the quantitatively of x
while(x>0){
int r=x%10;
int l=x/d;
if(r!=l)
return false;
x=x%d/10;
d/=100;
}
return true;
}
};