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 += i
11         h = 0
12         e = len(ss)-1
13         while(h<e):
14             if(ss[h] == ss[e]):
15                 h += 1
16                 e -= 1
17             else:
18                 break
19         if h>=e:
20             ret = True
21         return ret

 

相关文章:

  • 2022-12-23
  • 2021-12-25
  • 2021-07-22
  • 2021-04-06
  • 2021-08-22
  • 2021-07-20
  • 2022-12-23
  • 2021-06-02
猜你喜欢
  • 2021-12-19
  • 2021-09-27
  • 2021-07-27
  • 2022-01-13
  • 2021-08-16
  • 2021-06-30
  • 2022-01-13
相关资源
相似解决方案