9. 回文数

class Solution {
    public boolean isPalindrome(int x) {
        if (x < 0 || (x != 0 && x % 10 == 0)) {
            return false;
        }

        int result = 0;

        while (result <= x) {
            result = result * 10 + x % 10;

            if (result == x || result == x / 10) {
                return true;
            }

            x /= 10;
        }

        return false;
    }
}
image.png

你可能感兴趣的:(9. 回文数)