Advertisement
zhukov000

CBS

Nov 2nd, 2019
227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.40 KB | None | 0 0
  1. stack = []
  2. is_error = False
  3. for bracket in input():
  4.     if bracket == '(':
  5.         stack.append(')')
  6.     elif bracket == '[':
  7.         stack.append(']')
  8.     elif bracket == '{':
  9.         stack.append('}')
  10.     else:
  11.         if len(stack) == 0 or stack[-1] != bracket:
  12.             is_error = True
  13.             break
  14.         stack.pop()
  15. print("yes" if len(stack) == 0 and not is_error else "no")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement