본문으로 건너뛰기

125. Valid Palindrome

· 약 1분
Seokjae Lee
Software engineer

원문: https://doljae.tistory.com/160

[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](https://leetcode.com/problems/valid-palindrome/)

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() 정도?...