Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from collections import deque
- parentheses = deque(input())
- check = []
- while parentheses:
- current = parentheses.popleft()
- if current in "{[(":
- check.append(current)
- elif current in "}])" and check:
- if check.pop() + current not in "()[]{}":
- print("NO")
- break
- else:
- print("NO")
- break
- else:
- print("YES")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement