LeetCode刷题(C++)——Palindrome Number(Easy)
Determine whether an integer is a palindrome. Do this without extra space.
class Solution {
public:
bool isPalindrome(int x) {
if (x < 0)
return false;
int base = 1;
while (x / base >= 10)
base *= 10;
while(x){
if (x/base != x % 10) // x/base为最高位数字 x%10位最低位数字
return false;
x = (x%base) / 10; //去掉最高位数字和最低位数字
base /= 100;
}
return true;
}
};
还没有评论,来说两句吧...