We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 75e6d44 commit be09081Copy full SHA for be09081
1 file changed
โvalid-palindrome/dusunax.pyโ
@@ -0,0 +1,28 @@
1
+'''
2
+# Leetcode 125. Valid Palindrome
3
+
4
+use regex to filter out non-alphanumeric characters ๐
5
6
+## Time and Space Complexity
7
8
+```
9
+TC: O(n)
10
+SC: O(n)
11
12
13
+### TC is O(n):
14
+- iterating through the string just once to filter out non-alphanumeric characters.
15
16
+### SC is O(n):
17
+- creating a new string to store the filtered characters.
18
19
20
+class Solution:
21
+ def isPalindrome(self, s: str) -> bool:
22
+ if s is " ":
23
+ return True
24
25
+ reg = "[^a-z0-9]"
26
+ converted_s = re.sub(reg, "", s.lower())
27
28
+ return converted_s == converted_s[::-1]
0 commit comments