Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
No stack, no replace, no re! solution in Clear category for Brackets by vnkvstnk
COMPLETE = ["{}", "()", "[]"]
def checkio(s):
s = [x for x in s if x in "({[)}]"]
i = 0
while i < len(s) // 2: # First match must appear in first half of a correct expression
if s[i] + s[i + 1] in COMPLETE:
del s[i], s[i]
i -= i > 0 # i == 0: "()()[]{}", i > 0: "((([[{}]])))"
continue
i += 1
return not s
May 27, 2020