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 4d20a86 commit 01f7bb1Copy full SHA for 01f7bb1
valid-palindrome/bskkimm.py
@@ -0,0 +1,22 @@
1
+class Solution(object):
2
+ def isPalindrome(self, s):
3
+ """
4
+ :type s: str
5
+ :rtype: bool
6
7
+ only_al_nu = []
8
+
9
+ # "2 man, a plan, a canal: Panam2"
10
+ # 1. Delete non-alphanumeric elements and space
11
+ for cha in s:
12
+ if cha.isalpha() or cha.isnumeric():
13
+ if cha.isalpha():
14
+ cha = cha.lower()
15
+ only_al_nu.append(cha)
16
17
+ # 2. extract the last and first elements and check if they are same
18
+ while len(only_al_nu) > 1:
19
+ if only_al_nu.pop() != only_al_nu.pop(0):
20
+ return False
21
22
+ return True
0 commit comments