L2 : 올바른 괄호 Python

jhyunn·2023년 1월 12일
0

Programmers

목록 보기
20/69

L2 : 올바른 괄호 Python

https://school.programmers.co.kr/learn/courses/30/lessons/12909

def solution(s):
    t = 0
    for c in s:
        if c == ')': t -= 1
        else: t += 1
        if t < 0: return False
    if t != 0:
        return False
    return True

닫는 괄호 ')' 가 더 많이 나온 적이 있거나, 마지막에 '('와 ')'의 수가 다르면 안된다.

profile
https://github.com/Sungjeonghyun

0개의 댓글