9. Palindrome Number - Easy

方法一:

class Solution:
    def isPalindrome(self, x: int) -> bool:
        if x<0:
            return False
        if x<10:
            return True
        
        res=0
        num=x
        while x>0:
            ele=x%10
            x=x//10
            res=res*10+ele
            
        if res==num:
            return True
        else:
            return False

方法二:

class Solution:
    def isPalindrome(self, x: int) -> bool:
        if x<0:
            return False
        if x<10:
            return True
        s=str(x)
        if s==s[::-1]:
            return True

发布了170 篇原创文章 · 获赞 90 · 访问量 6396

猜你喜欢

转载自blog.csdn.net/weixin_45405128/article/details/104437917