题目:
Determine whether an integer is a palindrome. Do this without extra space.
Tags Math
Similar Problems (E)Palindrome Linked List
分析:
notes:不要忘记n为负的情况
代码:
class Solution {
public:
bool isPalindrome(int x) {
if(x<0)
return false;
int revBefore = x;
int revAfter = 0;
int remain = 0;
while(x!=0)
{
remain = x%10;
revAfter = revAfter*10+remain;
x = x/10;
}
if(revBefore==revAfter)
return true;
else
return false;
}
};