You are viewing a single comment's thread. Return to all comments →
Python 3
s = list(s) if len(s) % 2 != 0: return ('NO') char_dict = {"{":"}","[":"]",'(':')'} left_pt = 0 while s != []: starting = s[left_pt] if starting not in char_dict.keys(): return ('NO') target = char_dict[starting] if s[left_pt+1] == target: s.pop(left_pt) s.pop(left_pt) left_pt = 0 else: left_pt += 1 if left_pt == len(s)-1 and s != []: return ('NO') 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 →
Python 3