How about this?


  • 0
    B
    public class Solution {
        public boolean isPalindrome(int x) {
            if(x<0)
                return false;
            int len = Integer.toString(x).length();
            int i = (int)Math.pow(10,len-1);
            int j= (int)Math.pow(10,1);
            for(;;){
                if(x/i!=x%j){
                    return false;
                }else if(i>j){
                    x= x%i;
                    x/=j;
                    i=i/100;
                }else{
                    return true;
                }
            }
        }
    }
    

    The running times seems to fluctuate but passed all cases in less than 250ms.


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.