Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
extended iterable unpacking solution in Clear category for Digit Stack by David_Jones
def digit_stack(commands):
stack = []
digits_sum = 0
for command in commands:
op, *arg = command.split()
if op == 'PUSH':
stack.append(int(*arg))
elif stack:
digits_sum += stack[-1]
if op == 'POP':
stack.pop()
return digits_sum
May 21, 2019
Comments: