Easy java solution,no reverse


  • -3
    M

    public class Solution {
    public boolean isPalindrome(int x) {
    int a = x;
    int n = 1;

        if(a<0) return false;
        
        while(a/n>=10){
            n = n*10;
        }
        
        while(a>0){
            if((a/n) != (a%10)) return false;
            a = a%n;
            if(a<10) return true;
            a = a/10;
            n = n/100;
        }
        return true;
        
    }
    

    }


Log in to reply
 

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