Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
simple solution in Clear category for Digit Stack by ddavidse
def digit_stack(commands):
stack = []
out = 0
for command in commands:
if command[:4] == 'PUSH':
stack.append(int(command[5:]))
elif command[:3] == 'POP':
if stack:
out += stack.pop()
elif command[:4] == 'PEEK':
if stack:
out += stack[-1]
return out
Sept. 30, 2022