leetcode:Valid Palindrome【Python版】

时间:2023-01-27 15:29:48

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

2、注意是alphanumeric字符;

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

 class Solution:
# @param s, a string
# @return a boolean
def isPalindrome(self, s):
ret = False
s = s.lower()
ss = ""
for i in s:
if i.isalnum():
ss += i
h = 0
e = len(ss)-1
while(h<e):
if(ss[h] == ss[e]):
h += 1
e -= 1
else:
break
if h>=e:
ret = True
return ret