首页 > 其他 > 详细

125. Valid Palindrome

时间:2018-08-24 12:11:51      阅读:140      评论:0      收藏:0      [点我收藏+]

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

原文:https://www.cnblogs.com/jyg694234697/p/9528800.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!