Created
October 30, 2019 15:05
-
-
Save inspirit941/9cf258e06dc23cfe354784b2ccf4e81f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from collections import deque | |
def solution(s): | |
s = deque(list(s)) | |
stack = [] | |
stack.append(s.popleft()) | |
while s: | |
# stack이 비었으면 삽입 | |
if len(stack) == 0: | |
stack.append(s.popleft()) | |
# 스택 맨 앞값과 남은 string의 맨 앞 비교. | |
# 같을 경우 stack과 s에서 둘 다 제거한다. | |
elif stack[-1] == s[0]: | |
stack.pop() | |
s.popleft() | |
else: | |
# 값이 다르면, stack에 다음 string의 맨 앞 값을 넣는다. | |
stack.append(s.popleft()) | |
# stack에 값이 남아 있으면 짝지어 제거하기 실패한 것. | |
if len(stack) != 0: | |
return 0 | |
else: | |
return 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment