125. Valid Palindrome

Posted bernieloveslife

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了125. Valid Palindrome相关的知识,希望对你有一定的参考价值。

Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.

Note: For the purpose of this problem, we define empty string as valid palindrome.

Example 1:

Input: "A man, a plan, a canal: Panama"
Output: true

Example 2:

Input: "race a car"
Output: false

class Solution:
    def isPalindrome(self, s):
        """
        :type s: str
        :rtype: bool
        """
        if len(s)==0:
            return True
        str = []
        for i in s:
            if i.isalnum():
                str.append(i.lower())
        for i in range(int(len(str)/2)):
            if str[i]!= str[len(str)-i-1]:
                return False
        return True


以上是关于125. Valid Palindrome的主要内容,如果未能解决你的问题,请参考以下文章

125. Valid Palindrome

LeetCode 125. Valid Palindrome

125. Valid Palindrome(js)

125. Valid Palindrome

[LC] 125. Valid Palindrome

125. Valid Palindrome