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

 

以上

posted on 2018-08-24 11:28  jydd  阅读(53)  评论(0编辑  收藏  举报

导航