Skip to content

Commit 3806b53

Browse files
committed
valid-palindrome
1 parent b1952ce commit 3806b53

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

Strings/isvalidPalindrome.py

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
"Leetcode - https://leetcode.com/problems/valid-palindrome/"
2+
'''
3+
A phrase is a palindrome if, after converting all uppercase letters into lowercase letters and removing all non-alphanumeric characters, it reads the same forward and backward. Alphanumeric characters include letters and numbers.
4+
5+
Given a string s, return true if it is a palindrome, or false otherwise.
6+
7+
Example 1:
8+
9+
Input: s = "A man, a plan, a canal: Panama"
10+
Output: true
11+
Explanation: "amanaplanacanalpanama" is a palindrome.
12+
'''
13+
14+
15+
def isPalindrome(self, s):
16+
filtered_char = filter(lambda c: c.isalnum(), s)
17+
low_filterchar = map(lambda c: c.lower(), filtered_char)
18+
filt = list(low_filterchar)
19+
if filt == filt[::-1]:
20+
return True
21+
else:
22+
return False

0 commit comments

Comments
 (0)