682. Baseball Game
Practice Baseball Game for free on NudgeCode: Easy, Stack pattern. Write it in Python or JavaScript, run the tests in your browser, and ask for a hint when you are stuck.
You keep a record of scores, starting empty. Apply each string in operations in order:
- an integer
x: record a new scorex "+": record the sum of the previous two scores"D": record double the previous score"C": remove the previous score
Return the sum of all scores left in the record. Every operation is valid (there are always enough previous scores).
Example
operations = ["5","2","C","D","+"] -> 30 (record ends as [5,10,15])
Constraints
- 1 <= operations.length <= 1000
- integer scores are in [-3 * 10^4, 3 * 10^4]