leetcode 009

Palindrome Number

Determine whether an integer is a palindrome. Do this without extra space.

Method

Calculate the reverse number and compare.

Python code

class Solution(object):
    def isPalindrome(self, x):
        """
        :type x: int
        :rtype: bool
        """
        if x < 0:
            return False
        num = x
        r = 0
        while num:
            r = r * 10 + num % 10
            num = num / 10
        return r == x