https://leetcode.com/problems/valid-palindrome/description/
주어진 문자여열이 팰린드롬인지 확인하라.
대소문자를 구분하지 않으며, 영문자와 숫자만을 대상으로 한다.
Example 1:
Input: s = "A man, a plan, a canal: Panama"
Output: true
Explanation: "amanaplanacanalpanama" is a palindrome.
Example 2:
Input: s = "race a car"
Output: false
Explanation: "raceacar" is not a palindrome.
Example 3:
Input: s = " "
Output: true
Explanation: s is an empty string "" after removing non-alphanumeric characters.
Since an empty string reads the same forward and backward, it is a palindrome.
class Solution:
def isPalindrome(self, s: str) -> bool:
s_list = [alpha_num.lower() for alpha_num in s if alpha_num.isalnum()]
return s_list == s_list[::-1]