Coding Test
[Leetcode]125.Valid Palindrome
동만쓰
2022. 6. 24. 00:33
def isPalundrome(s):
strs=[]
for char in s:
if char.isalnum(): #영문자,숫자 여부를 판별하는 함수
strs.append(char.lower()) #대소문자 구분 안함
while len(str)>1: #홀수 고려해서 1
if strs.pop(0) != strs.pop(): #리스트의 pop은 인덱스를 지정할 수 있음
return False
return True
import collection
def isPalundrome(s):
strs=collection.deque()
for char in s:
if char.isalnum():
strs.append(char.lower())
while len(str)>1:
if strs.popleft() != strs.pop():
return False
return True
def isPalundrome(s):
s=s.lower()
s=re.sub('[^a-z0-9]','',s)
return s==s[::-1] #문자열 뒤집기