Determine whether an integer is a palindrome. Do this without extra space.
没明白这句话“Do this without extra space.”是什么意思,A完以后看了别人的讨论也都用到了局部变量。
class Solution {
public:
bool isPalindrome(int x) {
if (x < 0)
return false;
if (x == 0)
return true;
int reverse = 0;
int back_x = x;
while (x > 0)
{
reverse = reverse * 10 + x % 10;
x = x / 10;
}
if (back_x == reverse)
return true;
else
return false;
}
};