标签:
Determine whether an integer is a palindrome. Do this without extra space.
类似于reverse integer。
public class Solution {
public boolean isPalindrome(int x) {
if (x < 0) {
return false;
}
int scale = 1;
while (x / scale >= 10) {
scale *= 10;
}
while(x > 0) {
int l = x / scale;
int r = x % 10;
if (l != r) {
return false;
}
x = x % scale / 10;
scale /= 100;
}
return true;
}
}
标签:
原文地址:http://www.cnblogs.com/shini/p/4467918.html