Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Digit Stack by bukebuer
def digit_stack(commands):
stack, sum = [], 0
for cmd in commands:
if 'PUSH' in cmd:
stack.append(int(cmd.split(' ')[1]))
elif cmd=='POP':
sum += stack.pop() if stack else 0
else:
sum += stack[-1] if stack else 0
return sum
July 2, 2014
Comments: