Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
10-liner: Digits Stacked Perfectly solution in Clear category for Digit Stack by Stensen
def digit_stack(commands, answer=0):
stack = []
for command in commands:
if 'PUSH' in command:
stack.append(int(command[-1]))
if stack and 'POP' in command:
answer += stack.pop()
if stack and 'PEEK' in command:
answer += stack[-1]
return answer
Oct. 31, 2020