leetcode 9回文数

leetcode 9回文数_第1张图片

class Solution:
    def isPalindrome(self, x: int):
        if x<0:
            return False
        else:
        y = str(x)[::-1]
            if y == str(x):
                return True
            else:
                return False

我自己写的另一种:

class Solution(object):
    def isPalindrome(self, x):
        """
        :type x: int
        :rtype: bool
        """
        s1 = str(x)
        s2 = s1[::-1]
        if s1==s2:
            return True
        else:
            return False

 

 

你可能感兴趣的:(剑指offer)