首页 > 代码库 > leetcode:Valid Palindrome

leetcode:Valid Palindrome

1、注意空字符串的处理;

2、注意是alphanumeric字符;

3、字符串添加字符直接用+就可以;

 1 class Solution: 2     # @param s, a string 3     # @return a boolean 4     def isPalindrome(self, s): 5         ret = False 6         s = s.lower() 7         ss = "" 8         for i in s: 9             if i.isalnum():10                 ss += i11         h = 012         e = len(ss)-113         while(h<e):14             if(ss[h] == ss[e]):15                 h += 116                 e -= 117             else:18                 break19         if h>=e:20             ret = True21         return ret

 

leetcode:Valid Palindrome