Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- sequence = input()
- stack = []
- flag = True
- for ch in sequence:
- if ch in "({[":
- stack.append(ch)
- else:
- if len(stack) == 0:
- flag = False
- break
- last_opening_bracket = stack.pop()
- pair = f"{last_opening_bracket}{ch}"
- if pair not in "(){}[]":
- flag = False
- break
- if flag and len(stack) == 0:
- print("YES")
- else:
- print("NO")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement