125. Valid Palindrome

Posted jyg694234697

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.

 

技术分享图片

class Solution(object):
    def isPalindrome(self, s):
        """
        :type s: str
        :rtype: bool
        """
        s = s.lower()
        start_p,end_p = 0,len(s)-1
        while(start_p < end_p):
            if (s[start_p].isalnum() == False):
                start_p+=1
            elif (s[end_p].isalnum() == False):
                end_p-=1
            elif (s[start_p] != s[end_p]) :
                return False
            else:
                start_p+=1
                end_p-=1
        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