Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Uncategorized category for Digit Stack by Moff
def digit_stack(commands):
stack = []
result = 0
for row in commands:
cmd = row.split()
if cmd[0] == 'PUSH':
stack.append(int(cmd[1]))
elif cmd[0] == 'POP' and stack:
result += stack.pop(-1)
elif cmd[0] == 'PEEK' and stack:
result += stack[-1]
return result
July 23, 2015