Open minimanimoh opened 3 years ago
Question: why this code doesn't work?
def minimum_bracket_reversals(input_string):
if len(input_String) % 2 == 1:
return -1
stack = Stack()
count = 0
for bracket in input_String:
if stack.is_empty():
stack.push(bracket)
else:
top == stack.top()
if top != bracket:
if top == '{':
stack.pop()
countinue
stack.push(bracket)
ls = list()
while not stack.is_empty():
first = stack.pop()
second = stack.pop()
ls.append(first)
ls.append(second)
if first == '}' and second == '}':
count += 1
elif first == '{' and second == '}':
count += 2
elif first == '{' and second == '{':
count += 1
return count
What does 'if top! = bracket' indicate?
for bracket in input_String:
if stack.is_empty():
stack.push(bracket)
else:
top == stack.top()
if top != bracket:
if top == '{':
stack.pop()
countinue
stack.push(bracket)