Generic way? normal solution


  • 0
    public class Solution {
        public boolean isPalindrome(int x) {
            int i=0;
            if(x <0)
            return false;
            while((int)(x/Math.pow(10,i))>0)
            i++;
            for( int j=0; j<i/2 ;j++)
            {
                if((x/(int)(Math.pow(10,(i-j-1))))%10!=(int)(x/Math.pow(10,j))%10)
                return false;
            }
            return true;
        }
    }
    

    Do not open extra space, only one int flag


Log in to reply
 

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