STUDY/Algorithm

[프로그래머스] LEVEL2 올바른 괄호, python3

sinawi95 2020. 1. 7. 09:06
728x90

def solution(s):
    answer=False
    if len(s)%2 ==1:
        return False
    left=0
    right=0
    for cha in s:
        if cha=='(':
            left+=1
        elif cha==')':
            right+=1
        if left <right: 
            break
    if left==right:
            answer=True
    return answer