Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 3806b53

Browse files
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

Lines changed: 22 additions & 0 deletions
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)

AltStyle によって変換されたページ (->オリジナル) /