回文
class Solution:
def isPalindrome(self, x: int) -> bool:#self不用管 参数是int 型的x 函数返回结果是布尔型的
y = str(x)#str 就是一个python内置函数 就是读取字符串
return x >= 0 and y == y[::-1] #返回判断条件 要大于0且y=y的逆置 则为true 其他都为false
#类函数的调用方法1
sou =Solution()
sou.isPalindrome(121)
#类函数的调用方法2
Solution().isPalindrome(121)
#类函数的调用方法3 这种叫做未实例化类 会导致传的参数少一个 要在参数中加一个随便的数值参数原理未知
Solution.isPalindrome(1,121)
class Solution(object):
def isPalindrome(self, x):
"""
:type x: int
:rtype: bool
"""
y =str(x)
return x >= 0 and y == y[::-1]

浙公网安备 33010602011771号