Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
10 lines proc, simple solution in Clear category for Calculator-I by CDG.Axel
def calculator(log: str) -> str:
prev, current, new, operation = 0, 0, True, '='
for key in log:
if key.isdigit():
if new:
prev, current = current, 0
current, new = current * 10 + int(key), False
elif key in '+-=':
current = prev + current if operation == '+' else prev - current if operation == '-' else current
operation, new = key, True
return str(current)
Feb. 2, 2023
Comments: