Skip to content

Instantly share code, notes, and snippets.

@inspirit941
Created January 9, 2020 04:01
Show Gist options
  • Save inspirit941/48aaa5271ca2880786d78fc978bbc9b8 to your computer and use it in GitHub Desktop.
Save inspirit941/48aaa5271ca2880786d78fc978bbc9b8 to your computer and use it in GitHub Desktop.
n = int(input())
def check(brackets):
stack = []
for i in brackets:
if i == "(":
stack.append(i)
else:
# ")" 를 입력받았는데 이전에 "("를 입력받은 적이 없는 경우. VPS가 아니다.
if not stack:
print("NO")
return
else:
# stack에 "("가 있으므로 stack에서 "("를 꺼낸다.
stack.pop()
# 괄호를 전부 다 돌았는데 stack 안에 무언가가 남아 있으면 VPS가 아니다.
if not stack:
print("YES")
return
else:
print("NO")
return
for _ in range(n):
brackets = input()
check(brackets)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment