Advertisement
Guest User

Untitled

a guest
Sep 15th, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.39 KB | None | 0 0
  1. # you can write to stdout for debugging purposes, e.g.
  2. # print("this is a debug message")
  3.  
  4. def solution(S):
  5. # write your code in Python 3.6
  6. d = {"(":")","[":"]","{":"}"}
  7. stack = []
  8. for s in S:
  9. if s in d:
  10. stack.append(s)
  11. else:
  12. if stack == [] or d[stack.pop()] != s:
  13. return 0
  14. if stack != []:
  15. return 0
  16. return 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement