Skip to content

Commit 01f7bb1

Browse files
committed
"create the bskkimm.py
1 parent 4d20a86 commit 01f7bb1

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

valid-palindrome/bskkimm.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)