Advertisement
Nenogzar

6

May 14th, 2024
822
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.38 KB | None | 0 0
  1. from collections import deque
  2.  
  3. parentheses = deque(input())
  4. check = []
  5. while parentheses:
  6.     current = parentheses.popleft()
  7.     if current in "{[(":
  8.         check.append(current)
  9.     elif current in "}])" and check:
  10.         if check.pop() + current not in "()[]{}":
  11.             print("NO")
  12.             break
  13.     else:
  14.         print("NO")
  15.         break
  16. else:
  17.     print("YES")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement