Algorithm

125. Valid Palindrome

Doljae 2021. 6. 8. 11:20
 

Valid Palindrome - LeetCode

Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.

leetcode.com

1. isalnum()

class Solution:
    def isPalindrome(self, s: str) -> bool:
        stack = []
        for char in s:
            if char.isalnum():
                stack.append(char.lower())

        if len(stack) % 2 == 1:
            return stack[:len(stack) // 2] == stack[len(stack) // 2 + 1:][::-1]
        else:
            return stack[:len(stack) // 2] == stack[len(stack) // 2:][::-1]

건질 만한 건 isalnum() 정도?...