Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Digit Stack solution in Clear category for Digit Stack by JimmyCarlos
def digit_stack(commands):
stack,total_score = [],0
for command in commands:
if command.split()[0] == "PUSH":
stack.append(int(command.split()[1]))
elif command.split()[0] == "POP" and len(stack) > 0:
total_score += stack.pop()
elif command.split()[0] == "PEEK" and len(stack) > 0:
total_score += stack[-1]
return total_score
July 16, 2019