-
Notifications
You must be signed in to change notification settings - Fork 0
/
125.py
56 lines (38 loc) · 1.03 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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/env python
# -*- coding: utf-8 -*-
__author__ = ['"wuyadong" <[email protected]>']
class Solution(object):
def isPalindrome(self, s):
"""
:type s: str
:rtype: bool
"""
i = 0
j = len(s)-1
while i < j:
left_c = s[i]
while i < j:
left_c = s[i]
if left_c.isalnum():
break
else:
i += 1
if i == j:
break
right_c = s[j]
while i < j:
right_c = s[j]
if right_c.isalnum():
break
else:
j -= 1
if i == j:
break
if left_c.lower() != right_c.lower():
return False
i += 1
j -= 1
return True
if __name__ == "__main__":
print Solution().isPalindrome("A man, a plan, a canal: Panama")
print Solution().isPalindrome("race a car")