美文网首页LeetCode
125. 验证回文串

125. 验证回文串

作者: cptn3m0 | 来源:发表于2019-03-23 21:37 被阅读0次

    题外话

    简洁易懂的代码是好代码.

    注意事项

    1. python 字符判断是何种类型的写法
    2. 条件的处理, 使用 continue比较好
    class Solution(object):
        def isPalindrome(self, s):
            """
            :type s: str
            :rtype: bool
            """
            s = s.lower()
            l = 0
            r = len(s)-1
            
            while l<r:
                if s[l].isalnum() == False:
                    l=l+1
                    continue
                    
                if s[r].isalnum() == False:
                    r=r-1
                    continue
                    
                if s[l]==s[r]:
                    l=l+1
                    r=r-1
                else:
                    return False
                    
            return True    
    

    相关文章

      网友评论

        本文标题:125. 验证回文串

        本文链接:https://www.haomeiwen.com/subject/gfyevqtx.html