You are viewing a single comment's thread. Return to all comments →
def isBalanced(s): refi=['{', '[', '(', ')', ']', '}'] refe=['}', ']', ')'] z=list() if len(s) == 0: return 'YES' if len(s) % 2 == 1: return 'NO' if refi.index(s[0])>2 or refi.index(s[-1])<=2: return 'NO' for i in s: if refi.index(i)<3: z.append(refi.index(i)) else: if z and z[-1]-refe.index(i)==0: z.pop() else: return 'NO' if not z: return 'YES'
Seems like cookies are disabled on this browser, please enable them to open this website
Balanced Brackets
You are viewing a single comment's thread. Return to all comments →