public class Solution {
public boolean isPalindrome(int x) {
boolean result=false;
int digit=0,x3;
if(x<0)return false;
x3=x;
while(x3>0){
x3=x3/10;
digit++;
}
int i=digit,j=1,x1,x2;
while(i>j){
x1=(x%(int)Math.pow(10,i))/(int)Math.pow(10,i-1);
x2=(x%(int)Math.pow(10,j))/(int)Math.pow(10,j-1);
// System.out.println(x1+" "+x2);
if(x1!=x2)break;
else{
i--;
j++;
}
}
if(i<=j)result=true;
return result;
}
}
leetcode #9 Palindrome
最新推荐文章于 2024-09-09 18:27:53 发布