Leetcode9. Palindrome Number

回文需要注意一点:负数不是回文,负号是要被计算在内的。
题目描述: Determine whether an integer is a palindrome. Do this without extra space.
-----------------------------------------------------------------------------------------------------
python
class Solution(object):
    def isPalindrome(self, x):
        """
        :type x: int
        :rtype: bool
        """
        front = x
        reminder = 0
        result = 0 
        if front < 0:
            return False
        while x != 0:
            reminder = x % 10
            x = x / 10
            result = result * 10 + reminder
        if result == front:
            return True
        else:
            return False
题目很简单,和第七题差不多思想就是整数取反,字符串判断也是一种方法。


猜你喜欢

转载自blog.csdn.net/sinat_24648637/article/details/79586093