LeetCode--Python解析【Valid Palindrome】(125)

题目:

方法:

class Solution:
    def isPalindrome(self, s):
        """
        :type s: str
        :rtype: bool
        """
        a=''.join([x for x in s if x.isalpha() or x.isdigit()]).lower()
        print(a)
        if a == a[::-1]:
            return True
        return False

使用isdigit()和isalpha()判断是否为数字和字母

isdigit()判断是否为数字

isalpha()判断是否为字母

再判断是否为回文字符串。

猜你喜欢

转载自blog.csdn.net/ZJRN1027/article/details/81285382
今日推荐