Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Digit Stack by fed.kz
def digit_stack(commands):
stack = []
total = 0
for com in commands:
if 'PUSH' in com:
stack.append(int(com[5:]))
elif com == 'POP' and stack:
total += stack.pop()
elif stack: total += stack[-1]
return total
Oct. 19, 2018