๋ฌธ์
https://school.programmers.co.kr/learn/courses/30/lessons/12909
ํ์ด
# ํ๋ก๊ทธ๋๋จธ์ค 2๋จ๊ณ - ์คํ/ํ - ์ฌ๋ฐ๋ฅธ ๊ดํธ
def solution(s):
answer = True
stack = []
for t in s:
if t == '(':
stack.append(t)
elif len(stack) and t == ')':
stack.pop()
else:
return False
return False if len(stack) else True
stack์ ์ฌ๋ ๊ดํธ๊ฐ ๋์ค๊ฒ ๋๋ฉด append ํด์ฃผ๊ณ ๋ซ๋ ๊ดํธ๊ฐ ๋์ค๋ฉด pop ํด์ค๋ค.
๋ง์ง๋ง์ stack์ ์์๊ฐ ์กด์ฌํ๋ค๋ฉด ์๋ชป๋ ๊ดํธ์ด๋ค.