Skip to content

Commit 9f4c8a9

Browse files
week 3: Valid Palindrome
1 parent 87b6ad0 commit 9f4c8a9

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

valid-palindrome/prograsshopper.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
class Solution:
2+
def isPalindrome(self, s: str) -> bool:
3+
formatted_string = "".join(elem.lower() for elem in s if elem.isalnum())
4+
5+
# sol 1
6+
return formatted_string == formatted_string[::-1]
7+
8+
# sol 2
9+
left = 0
10+
right = len(formatted_string) - 1
11+
while left < right:
12+
if formatted_string[left] != formatted_string[right]:
13+
return False
14+
left += 1
15+
right -= 1
16+
return True

0 commit comments

Comments
 (0)