Advertisement
Guest User

Untitled

a guest
Mar 21st, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.36 KB | None | 0 0
  1. s = "((([]){}))"
  2.  
  3. stack = []
  4. good = True
  5. for c in s:
  6.     if c in '[{(':
  7.         stack.append(c)
  8.     elif c in ')}]':
  9.         if not stack:
  10.             good = False
  11.             break
  12.         opening = stack.pop()
  13.         if opening + c not in ['()', '[]', '{}']:
  14.             good = False
  15.             break
  16. if stack:
  17.     good = False
  18.  
  19. print(s, 'is', good)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement