leetcood学习笔记-9

题目描述

方法一:转换为字符串

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

方法二;数字反转

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

猜你喜欢

转载自www.cnblogs.com/oldby/p/10502084.html