-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathValidPalindrome.py
More file actions
24 lines (22 loc) · 982 Bytes
/
ValidPalindrome.py
File metadata and controls
24 lines (22 loc) · 982 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
class Solution:
# @param s, a string
# @return a boolean
def isPalindrome(self, s):
start = 0
end = len(s) - 1
while start <= end:
if ((ord(s[start]) >= 48 and ord(s[start]) <= 57) or (ord(s[start]) >= 65 and ord(s[start]) <= 90) or (ord(s[start]) >= 97 and ord(s[start]) <= 122)) and\
((ord(s[end]) >= 48 and ord(s[end]) <= 57) or (ord(s[end]) >= 65 and ord(s[end]) <= 90) or (ord(s[end]) >= 97 and ord(s[end]) <= 122)):
if s[start].lower() != s[end].lower():
break
else:
start += 1
end -= 1
else:
if (ord(s[start]) >= 48 and ord(s[start]) <= 57) or (ord(s[start]) >= 65 and ord(s[start]) <= 90) or (ord(s[start]) >= 97 and ord(s[start]) <= 122):
end -= 1
else:
start += 1
else:
return True
return False