Advertisement
Guest User

Untitled

a guest
Jun 28th, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.57 KB | None | 0 0
  1. def braces(values):
  2.     opening_braces = ['(','{','[']
  3.     closing_braces = [')','}',']']
  4.     result = list()
  5.     for value in values:
  6.         stack = list()
  7.         ind = False
  8.         for i in range(len(value)):
  9.             if opening_braces.__contains__(value[i]):
  10.                 stack.append(opening_braces.index(value[i]))
  11.             elif closing_braces.__contains__(value[i]):
  12.                 if len(stack) == 0:
  13.                     print('NO')
  14.                     ind = True
  15.                     break
  16.                 elif closing_braces.index(value[i]) == stack[-1]:
  17.                     stack.pop()
  18.         if not ind:
  19.             if len(stack) == 0:
  20.                 print('YES')
  21.             else:
  22.                 print('NO')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement