-
-
Notifications
You must be signed in to change notification settings - Fork 300
/
125.py
29 lines (28 loc) · 1.07 KB
/
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
__________________________________________________________________________________________________
sample 28 ms submission
class Solution:
def isPalindrome(self, s: str) -> bool:
ignore_chars = ',./<>?;\':"[]\{}|`~!@#$%^&*()-=_+ '
for char in ignore_chars:
if char in s:
s = s.replace(char,'')
return s.lower() == s.lower()[::-1]
__________________________________________________________________________________________________
sample 13024 kb submission
class Solution:
def isPalindrome(self, s: str) -> bool:
s = s.lower()
l, r = 0, len(s) - 1
while (l < r):
if s[l].isalnum() and s[r].isalnum():
if s[l] != s[r]:
return False
else:
l += 1
r -= 1
elif s[l].isalnum():
r -= 1
elif not s[l].isalnum():
l += 1
return True
__________________________________________________________________________________________________