[LeetCode] 125. Valid Palindrome
Python
class Solution:
def isPalindrome(self, s: str) -> bool:
strs = []
for i in s:
if i.isalnum():
strs.append(i.lower())
while len(strs) > 1:
if strs.pop(0) != strs.pop():
return False
return True
#deque
class Solution:
def isPalindrome(self, s: str) -> bool:
strs: Deque = collections.deque()
for i in s:
if i.isalnum():
strs.append(i.lower())
while len(strs) > 1:
if strs.popleft() != strs.pop():
return False
return True
댓글남기기