You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# 1) Iterate through the string using two-pointers, skipping non-alphanumeric characters and comparing them in lowercase to validate the palindrome in-place.
2
+
# TC: O(N) where N is the length of s
3
+
# SC: O(1)
4
+
classSolution:
5
+
defisPalindrome(self, s: str) ->bool:
6
+
left=0
7
+
right=len(s) -1
8
+
9
+
whileleft<right:
10
+
ifnots[left].isalnum():
11
+
left+=1
12
+
continue
13
+
ifnots[right].isalnum():
14
+
right-=1
15
+
continue
16
+
17
+
ifs[left].lower() !=s[right].lower(): returnFalse
18
+
left+=1
19
+
right-=1
20
+
21
+
returnTrue
22
+
23
+
# 2) Filter alphanumeric characters and conver them to lowercase to create a new string and then simply validate palindrome using two-pointers
0 commit comments