9. Palindrome Number

class Solution {
    public boolean isPalindrome(int x) {
        if (x == 0) {
            return true;
        }
        // If it's negative number, or it ends with zero, it cannot be palindorme
        if (x < 0 || x % 10 == 0) {
            return false;
        }
        
        // get the reverted number of the second half,
        // get the number of the first half
        int reverted = 0;
        while (x > reverted) {
            reverted = 10 * reverted + x % 10;
            x /= 10;
        }

        // compare them
        return x == reverted || x == reverted / 10;
    }
}