Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Brackets by vlad_palovic
# migrated from python 2.7
def checkio(expression):
bra_ket = {
")" : "(",
"]" : "[",
"}" : "{",
}
stack = []
for ch in expression:
if ch in list(bra_ket.values()):
stack.append(ch)
elif ch in list(bra_ket.keys()):
if len(stack) == 0: return False
if stack.pop() != bra_ket[ch]:return False
if len(stack) != 0: return False
return True
May 28, 2016