Determine whether an integer is a palindrome. Do this without extra space.
/**
* 判断整数是否为回文,
* 负数不是,10整数倍不是.0~9是.
* Created by ustc-lezg on 16/4/6.
*/
public class Solution {
public boolean isPalindrome(int x) {
if (x < 0) {
return false;
}
if (x < 10) {
return true;
}
if (x % 10 == 0) {
return false;
}
int y = 0;
while (x > y) {
y = y * 10 + x % 10;
x /= 10;
}
if (y > x) {//x为奇数,y > x
y /= 10;
}
return x == y ? true : false;
}
}