• + 0 comments

    Python 3:

    Write your code here

    stack = []
    pairs = {
        '[': ']',
        '{': '}',
        '(': ')'
    }
    
    for bracket in s:
        if bracket in pairs:
            stack.append(bracket)
        elif not stack or pairs.get(stack.pop(-1)) != bracket:
            return 'NO'
    
    return 'YES' if not stack else 'NO'