Skip to content

Commit a9af198

Browse files
committed
Valid palindrome
1 parent 63dac45 commit a9af198

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

valid-palindrome/EstherKim97.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
class Solution(object):
2+
def isPalindrome(self, s):
3+
import re
4+
# remove all non-alphanumeric characters
5+
s = re.sub(r'\W+', '', s.lower())
6+
7+
# check if the string is equal forward and backward
8+
for i in range(len(s)//2):
9+
if s[i] != s[-(i+1)]:
10+
return False
11+
return True

0 commit comments

Comments
 (0)