class Solution {
public:
bool isPalindrome(int x)
{
if( x < 0 )
return false;
int count = 1;
int p = x;
while( p/10 != 0){
count++;
p /= 10;
}
for(int i = 0; i < count/2; i++){
int left = x / pow(10, count-i-1);
int right = x / pow(10,i);
if (left % 10 == right % 10)
continue;
else
return false;
}
return true;
}
};
[LeetCode] Palindrome Number
最新推荐文章于 2021-10-15 15:40:03 发布