https://leetcode.com/problems/valid-palindrome/
Solutions
step1: apply .isalnum() on each character for filtering out all the alphanumeric characters in the given string .
step2: compare filtered list with the one in reversed order, if they're identical with each other, we got the string with pattern of palindrome
Submissions
- faster than 98.95%
class Solution:
def isPalindrome(self, s: str) -> bool:
result=''
for i in s:
if i.isalnum():
result+=i.lower()
if result==result[::-1]:
return True
return False
Top comments (0)