Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
use queue solution in Clear category for Brackets by kdim
def checkio(expression):
m = dict(zip('({[',')}]')) # create dict '(':')','[':']','{':'}'
q = [] # use queue
for l in expression:
if l in m:
q.append(m[l]) # if left bracket, then add it to queue
elif l in m.values() and not (q and l==q.pop()): # if righ bracket, then remove it from queue
return False # but if queue is empty then return False
return not q # return True\False
Jan. 10, 2021
Comments: