题目:
Determine whether an integer is a palindrome. Do this without extra space.
解题思路:
负数不是回文数字,想办法在不增加额外空间的情况下将数字反转。
代码:
public boolean isPalindrome(int x) {
int copy = x;
int res = 0;
if (x < 0)
return false;
while (copy != 0) {
res = 10 * res + copy % 10;
copy = copy / 10;
}
if (x == res)
return true;
else
return false;
}