http://oj.leetcode.com/problems/palindrome-number/
Determine whether an integer is a palindrome. Do this without extra space.
注意:负数全部返回false,小于10的自然数都返回true。
参考代码:
class Solution {
public:
bool isPalindrome(int x) {
if(x < 0)
{
return false;
}
if(x<10)
{
return true;
}
int y = x, sum = x%10;
while(y / 10)
{
y /= 10;
sum = sum*10+y%10;
}
return sum==x;
}
};