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() 정도?...
'Algorithm' 카테고리의 다른 글
341. Flatten Nested List Iterator (0) | 2021.06.13 |
---|---|
172. Factorial Trailing Zeroes (0) | 2021.06.10 |
118. Pascal's Triangle (0) | 2021.06.07 |
26. Remove Duplicates from Sorted Array (0) | 2021.06.06 |
13. Roman to Integer (0) | 2021.05.31 |