Balanced Brackets

  • + 0 comments
    from functools import reduce
    
    def isBalanced(s):
        return 'NO' if reduce(lambda x, y: x.replace('()', '').replace('[]', '').replace('{}', ''), s[:len(s)//2+1], s) else 'YES'