Skip to content

Commit 3251a99

Browse files
committed
valid palindrome solution
1 parent 638a517 commit 3251a99

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

valid-palindrome/jylee2033.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
class Solution:
2+
def isPalindrome(self, s: str) -> bool:
3+
# 1. Remove non-alphanumeric characters and convert to lowercase
4+
# 2. Compare with reversed string
5+
6+
cleaned_s = ""
7+
for ch in s:
8+
if ch.isalnum():
9+
cleaned_s += ch.lower()
10+
11+
return cleaned_s == cleaned_s[::-1]
12+
13+
# Time Complexity : O(n)
14+
# Space Complexity : O(n)

0 commit comments

Comments
 (0)