9.Palindrome Number (INT)
2593 ワード
Determine whether an integer is a palindrome. Do this without extra space.
class Solution {
public:
bool isPalindrome(int x) {
if(x < 0) return false; //
if(x == 0) return true;
int tmp = x/10;
int pHead = 1;
int leftDigit, rightDigit, base;
while(tmp){
pHead*=10;
tmp /= 10;
}
while(pHead >= 1){
leftDigit = x/pHead;
rightDigit = x%10;
if(leftDigit != rightDigit) return false;
x %= pHead;
x /= 10;
pHead /= 100;
}
return true;
}
};