class Solution {
public:
bool isPalindrome(int x) {
if(x<0)
return false;
if(x==0)
return true;
int base=1;
while(x/base>=10)
{
base*=10;
}
int leftnum,rightnum;
while(x)
{
leftnum=x/base;
rightnum=x%10;
if(leftnum!=rightnum)
{
return false;
}
x-=leftnum*base;
base/=100;
x/=10;
}
return true;
}
};
【LeetCode】Palindrome Number
最新推荐文章于 2015-03-05 11:49:30 发布