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 c80e2b7 commit f886424Copy full SHA for f886424
valid-palindrome/joon.py
@@ -0,0 +1,19 @@
1
+import re
2
+
3
4
+class Solution:
5
+ # Time: O(n)
6
+ # Space: O(1)
7
+ def isPalindrome(self, s: str) -> bool:
8
+ # 1. Convert string
9
10
+ # Space: O(n) since re.sub() will internally use a new string of length n.
11
+ s = re.sub('[^a-z0-9]', '', s.lower())
12
+ length = len(s)
13
+ # 2. Check if the string reads the same forward and backward, one by one.
14
15
16
+ for i in range(length):
17
+ if (s[i] != s[length - 1 - i]):
18
+ return False
19
+ return True
0 commit comments