프로그래머스/Lv. 2
1. 올바른 괄호 (stack)
Seohyeong Lee
2024. 7. 17. 03:03
유형 : 스택 / 큐
풀이 시간 : 5분
def solution(s):
slist = list(s)
stack = []
for i in range(len(slist)):
if slist[i] == '(':
stack.append('(')
else:
if stack and stack[len(stack)-1] == '(':
del stack[len(stack)-1]
else:
return False
if stack:
return False
return True
괄호는 대표적인 stack을 활용하는 문제이다.