Determine whether an integer is a palindrome. Do this without extra space.
判断是否为回文数。
我的代码:
class Solution {
public boolean isPalindrome(int x) {
if(x<0) return false;
if(x<10) return true;
int x1 = x;
int num = 1;
while (x1>=10){
x1 = x1/10;
num++;
}
int[] array = new int[num];
for(int i=num-1;i>=0;i--){
array[i] = x%10;
x = x/10;
}
for(int i=0;i<num/2;i++){
if(array[i]!=array[num-1-i])break;
if(i+1>=num/2){
return true;
}
}
return false;
}
}