【LeetCode】9. Palindrome Number

class Solution_1:
    def isPalindrome(self, x):
        """
        :type x: int
        :rtype: bool
        """
        if x < 0 or (x!=0 and x%10==0):
            return False
        result = 0
        while x > result:
            result = result*10 + x % 10
            x = x // 10

        return (result == x) or (result//10 == x)


class Solution_2:
    def isPalindrome(self, x):
        """
        :type x: int
        :rtype: bool
        """
        x = str(x)
        return x == x[::-1]

猜你喜欢

转载自blog.csdn.net/zzc15806/article/details/81180717