Problem
You are keeping the scores for a baseball game with strange rules. At the beginning of the game, you start with an empty record. You are given a list of stringsoperations, where operations[i] is the ith operation you must apply to the record and is one of the following:
- An integer
x.- Record a new score of
x.
- Record a new score of
'+'.- Record a new score that is the sum of the previous two scores.
'D'.- Record a new score that is the double of the previous score.
'C'.- Invalidate the previous score, removing it from the record.
Examples
Constraints
- 1 <= operations.length <= 1000
operations[i]is"C","D","+", or a string representing an integer in the range [-3 * 10^4, 3 * 10^4].- For operation
"+", there will always be at least two previous scores on the record. - For operations
"C"and"D", there will always be at least one previous score on the record.