-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path125. 验证回文串.py
40 lines (33 loc) · 881 Bytes
/
125. 验证回文串.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# -*- encoding: utf-8 -*-
'''
@File : 125. 验证回文串.py
@Time : 2020/04/29 17:08:15
@Author : windmzx
@Version : 1.0
@Desc : For leetcode template
'''
# here put the import lib
from typing import List
class Solution:
def isPalindrome(self, s: str) -> bool:
s = s.lower()
i = 0
j = len(s)-1
while i < j:
if not self.isNumorChar(s[i]):
i+=1
continue
if not self.isNumorChar(s[j]):
j-=1
continue
if s[i]!=s[j]:
return False
i+=1
j-=1
return True
def isNumorChar(self,i):
numi=ord(i)
return (numi >= 48 and numi <= 57) or(numi >= 97 and numi <= 122)
if __name__ == "__main__":
x = Solution()
print(x.isPalindrome("ab a"))