11 ms Java 10 line without %


  • 2
    W
    public static boolean isPalindrome(int x) {
        if (x < 0) return false;
        if (x < 10) return true;
        int mirror = 0, dx = x, t;
        while (x >= 10) {
            t = x / 10;
            mirror += x - t * 10;
            mirror *= 10;
            x = t;
        }
        return dx - (mirror+x) == 0;
    }
    

    idk but it's solution bit over 75% solution, who is those 25% and how to improve ? ( i was try bit operations, but it's useless).


Log in to reply
 

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