不转为字符串
class Solution {
public boolean isPalindrome(int x) {
if(x<0)
return false;
int y = x;
int m = 0;
while(y>0){
m = m*10 + y%10;
y = y/10;
}
return m==x;
}
}
转成字符串
public boolean isPalindrome(int x) {
if(x<0){
return false;
}
String strX = String.valueOf(x);
for(int i=0;i<strX.length()/2;i++){
if(strX.charAt(i)!=strX.charAt(strX.length()-i-1)){
return false;
}
}
return true;
}