class Solution {
public:
bool isPalindrome(int x) {
int wei = 1;
int result = x;
if( x < 0)
return false;
while(result >= 10){
wei++;
result /= 10;
}
for(int i=0;i< wei/2;i++){
//0 to wei-1,1 to wei-2 and so on
int back = x/zero(i)%10;
int front = x/zero(wei - i -1)%10;
if( back != front)
return false;
}
return true;
}
private:
int zero(int wei){
int result = 1;
while(wei--)
result *= 10;
return result;
}
};
Palindrome Number
最新推荐文章于 2017-07-20 20:20:47 发布