题目:
Determine whether an integer is a palindrome. Do this without extra space.
Subscribe to see which companies asked this question.
解析:這个题目极为简单,主要弄清什么是回文数即可,可以上网查查。
程序:
class Solution {
public:
bool isPalindrome(int x) {
if(x<0|| (x!=0 &&x%10==0)) return false;
int sum=0;
while(x>sum)
{
sum = sum*10+x%10;
x = x/10;
}
return (x==sum)||(x==sum/10);
}
};