-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathValidPalindrome.py
More file actions
39 lines (33 loc) · 849 Bytes
/
ValidPalindrome.py
File metadata and controls
39 lines (33 loc) · 849 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
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
class Solution:
# @param s, a string
# @return a boolean
def isPalindrome(self, s):
if s == '':
return True
s2 = clean(s)
return palindrome(s2)
def clean(s):
s2 = []
for i in list(s):
if (i >= '0' and i <= '9') or (i >= 'a' and i <='z') or (i >= 'A' and i <= 'Z'):
s2.append(i.upper())
return s2
def palindrome(s):
mid = len(s)/2
if isOdd(s):
# stehets
for i in range(mid):
if s[mid-i-1] != s[mid+i+1]:
return False
return True
else:
# sefhhfes
for i in range(mid):
if s[mid+i] != s[mid-1-i]:
return False
return True
def isOdd(s):
if len(s) % 2 == 0:
return False
else:
return True