题目:Determine whether an integer is a palindrome. Do this without extra space.
大致意思:判断整数是否回文,不需要额外空间。
对于“Do this without extra space” 我以为是不需要再申请变量空间,懵逼》》》
查看solution中发现还是有申请变量,OK!
class Solution {
public boolean isPalindrome(int x) {
int n=x;
if (x < 0 || (x % 10 == 0 && x != 0))
return false;
int temp = 0;
while (x != 0) {
temp = temp * 10 + x % 10;
x = x / 10;
}
return temp == n || temp/10 == n;
}
}