We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 87b6ad0 commit 9f4c8a9Copy full SHA for 9f4c8a9
valid-palindrome/prograsshopper.py
@@ -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