Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def match(a, b):
- if a == '(' and b == ')':
- return True
- if a == '[' and b == ']':
- return True
- if a == '{' and b == '}':
- return True
- return False
- s = input()
- stack = list()
- for i in s:
- if i in ('(', '[', '{'):
- stack.append(i)
- else:
- if len(stack) == 0 or not match(stack[-1], i):
- print('NO')
- exit()
- else:
- stack.pop()
- if len(stack) == 0:
- print('YES')
- else:
- print('NO')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement