728x90
반응형
[문제]
괄호 검사
[코드]
List를 Stack 처럼 사용하여 풀이
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(S):
# write your code in Python 3.6
stackS = []
for i in S :
if not stackS :
stackS.append(i)
elif stackS[-1]=='{' and i == '}' :
stackS.pop()
elif stackS[-1] == '(' and i == ')' :
stackS.pop()
elif stackS[-1] == '[' and i == ']' :
stackS.pop()
else :
stackS.append(i)
if not stackS :
return 1
else :
return 0
728x90
'기타 > Codility' 카테고리의 다른 글
[Easy] Dominator (0) | 2022.05.26 |
---|---|
[Easy] Fish (0) | 2022.05.26 |
[Easy] Distinct (0) | 2022.05.25 |
[Easy] PassingCars (0) | 2022.05.24 |
[Easy] FrogJmp (0) | 2022.05.22 |