"""
from https://leetcode.com/problems/palindrome-number/
"""


class Solution(object):
    def isPalindrome(self, x):
        """
        :type x: int
        :rtype: bool
        """
        s = str(x)
        pivot = int(len(s) / 2)
        i = 0  # start at 0. If you start at 1, the even case does NOT compare the two core characters, e.g., 2 and 3 in '0230'.

        if len(s) <= 1:
            return True

        if len(s) % 2 == 0:
            # even (core of 2)
            while (pivot - i - 1) >= 0 and (pivot + i) < len(s):
                if s[pivot - i - 1] != s[pivot + i]:
                    break
                i += 1
            if pivot - i - 1 < 0:
                return True
        else:
            # odd (core of 1)
            while (pivot - i) >= 0 and (pivot + i) < len(s):
                if s[pivot - i] != s[pivot + i]:
                    break
                i += 1

            if pivot - i < 0:
                return True

        return False
