Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
([{cool}[]{}]()) solution in Speedy category for Brackets by timiway
def isOpener(c):
return (c == '(' or c == '{' or c == '[')
def isCloser(c):
return (c == ')' or c == '}' or c == ']')
def test(o,c):
return ((o == '(' and c == ')') or (o == '{' and c == '}') or (o == '[' and c == ']'))
def checkio(expression):
pile = []
for i in range(len(expression)):
if isOpener(expression[i]):
pile.append(expression[i])
if isCloser(expression[i]):
if pile == []:
return False
if test(pile[-1],expression[i]):
del pile[-1]
else:
return False
if pile == []:
return True
return False
#These "asserts" using only for self-checking and not necessary for auto-testing
May 12, 2014
Comments: