side = "(())()" stack = [] for i in range(len(side)): if side[i] == '(': stack.append('(') else: del stack[0] if len(stack) == 0: print("YES") else: print("NO")
To embed this project on your website, copy the following code and paste it into your website's HTML: