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