Determine whether an integer is a palindrome. Do this without extra space.
思路:暂时没有什么好的方法,判断数字的位数,然后判断对称位置上的数字是否相同,想到新方法再来更吧
public class Solution {
public boolean isPalindrome(int x) {
if (x < 0) return false ;
if ( x < 10) return true;
if ( x < 100){
if (x / 10 == x %10 ) return true;
else return false;
}
else if ( x < 1000){
if (x / 100 == x %10 ) return true;
else return false;
}
else if ( x < 10000){
if (x / 1000 == x %10 && (x%1000)/100 == (x/10)%10 ) return true;
else return false;
}
else if ( x < 100000){
if (x / 10000 == x %10 && (x%10000)/1000 == (x/10)%10 ) return true;
else return false;
}
else if ( x < 1000000){
if (x / 100000 == x %10 && (x/10000)%10 == (x/10)%10 && (x/1000)%10 == (x/100)%10 ) return true;
else return false;
}
else if ( x < 10000000){
if (x / 1000000 == x %10 && (x/100000)%10 == (x/10)%10 && (x/10000)%10 == (x/100)%10 ) return true;
else return false;
}
else if ( x < 100000000){
if (x / 10000000 == x %10 && (x/1000000)%10 == (x/10)%10 && (x/100000)%10 == (x/100)%10 && (x/10000)%10 == (x/1000)%10 ) return true;
else return false;
}
else if ( x < 1000000000){
if (x / 100000000 == x %10 && (x/10000000)%10 == (x/10)%10 && (x/1000000)%10 == (x/100)%10 && (x/100000)%10 == (x/1000)%10 ) return true;
else return false;
}
else if ( x < 2147483647){
if (x / 1000000000 == x %10 && (x/100000000)%10 == (x/10)%10 && (x/10000000)%10 == (x/100)%10 && (x/1000000)%10 == (x/1000)%10 && (x/100000)%10 == (x/10000)%10 ) return true;
else return false;
}
else return false;
}
}