Java easy to understand solution.


  • 1
    C
    public boolean isPalindrome(int x) {
        if (x < 0 || (x > 0 && x%10 == 0)) {
            return false;
        }
        int num = 0;
        while (x > num) {
            num = num * 10 + x % 10;
            x /= 10;
        }
        return x == num || num/10 == x;
    }

Log in to reply
 

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