entries come in order, and each one is one of:
- an integer x: add the score x to the log;
- "+": add a score equal to the sum of the last two scores in the log;
- "D": add twice the last score;
- "C": cancel the last score and strike it from the log.
Return the sum of all scores left in the log after every entry is processed. The entries are always valid: before "+" the log has at least two scores, and before "D" or "C" it has at least one.entries=["4", "7", "+", "C", "D"] → 25
The log goes [4] → [4, 7] → [4, 7, 11] → "C" removes 11: [4, 7] → "D" adds 14: [4, 7, 14]. The total is 25.
entries=["-3", "D", "8", "+"] → 1
[-3] → [-3, -6] → [-3, -6, 8] → [-3, -6, 8, 2]. The total is 1.
entries=["9", "C"] → 0
The only score is cancelled, the log is empty, so the total is 0.
entries.length ≤ 1000entries[i] is "+", "D", "C", or an integer from -3·10⁴ to 3·10⁴entries=["4", "7", "+", "C", "D"]
25
Run checks the first 3 tests in your browser. Submit checks all 74 tests on the server, hidden ones included.