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;
int l=(int)Math.log10(x)+1;
for(int i=l/2;i>=1;i--)
{
int r100=(int)Math.pow(10,i);
int l100=(int)Math.pow(10,l-i);
int rc=x%r100;
int lc=x/l100;
int rcl=(int)Math.log10(rc)+1;
int lcl=(int)Math.log10(lc)+1;
if(lcl>1)
{
if((rc<10)&&(lc%((int)Math.pow(10,lcl))==0))
if(rc%10==lc/(int)Math.pow(10,lcl))
{
if(l-rc-lc==0)
return true;
else
return isPalindrome((x/r100)%10);
}
}
else if(lcl==1&&rc==lc)
if(l-rc-lc==0)
return true;
else
return isPalindrome((x/r100)%10);
}
return false;
}
}
Why You should make money with online betting sites? - Work
ReplyDeleteFind out why you should be taking advantage of the promotions and promotions that หารายได้เสริม offer free spins and free bets when you join an online betting