Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Brackets by virzen
def checkio(expression):
openingBrackets = [ '(', '{', '[' ]
closingBrackets = [ ')', '}', ']' ]
stack = []
for char in list(expression):
if char in openingBrackets:
stack.append(char)
elif char in closingBrackets:
if len(stack) < 1:
return False
if stack[-1] != openingBrackets[closingBrackets.index(char)]:
return False
stack.pop()
return len(stack) == 0
Dec. 11, 2016