BOJ9012-괄호

Ok Haeeun·2023년 3월 29일
0

Python3로 algorithm문풀

목록 보기
37/53

괄호가 잘 열리고 잘 닫혀서 짝이 맞는지 확인하는 문제
그닥 오래걸리진 않았다.

저번에 프로그래머스 0레벨 문제 풀었다가 살짝쿵 현타왔었다^^
그치만 매일 풀려면 난 백준으로 일단 가야겠어...
맨날 현타맞으면서 어떻게 코딩허냐..!

import sys

n = int(sys.stdin.readline().rstrip('\n'))

while n>0:
    parenthesis = list(sys.stdin.readline().rstrip('\n'))
    open, close = 0,0
    isParenthesis = True
    for _ in range(len(parenthesis)):
        if parenthesis.pop() == ')':
            close += 1
        elif open < close: open += 1
        else:
            isParenthesis = False
            break
    if open == close and isParenthesis :print('YES')
    else: print('NO')
    n -= 1
profile
tistory에 이어서 기록합니다 👉 https://i-m-okay.tistory.com/

0개의 댓글

관련 채용 정보