Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Fast brackets solution in Speedy category for Brackets by hanpari
#I believe this is fast solution because it is going through only one iteration.
#If I am wrong let me know :)
def checkio(eq):
res = [0] #to avoid pop() from empty list in case of ")1+3"
for c in eq:
if c in ("(","[","{"):
res.append(c)
elif c == ")" and "("!= res.pop():
return False
elif c == "]" and "["!= res.pop():
return False
elif c == "}" and "{"!= res.pop():
return False
res.pop(0)
return not res
#These "asserts" using only for self-checking and not necessary for auto-testing
April 24, 2014
Comments: