You are keeping score for a baseball game with special rules. At the beginning, the record is empty.
You are given an array of strings operations, where operations[i] is the operation to apply at index i:
An integer x: Add a new score of
"+": Add a new score that is the sum of the previous
"D": Add a new score that is double the previous score.
"C": Invalidate and remove the previous score from the record.
Return the sum of all scores present on the record after applying all the operations.
Constraints:
operations.length
operations[i] is "C", "D", "+", or a string representing an integer in the range
For operation "+", there will always be at least
For operations "C" and "D", there will always be at least
You are keeping score for a baseball game with special rules. At the beginning, the record is empty.
You are given an array of strings operations, where operations[i] is the operation to apply at index i:
An integer x: Add a new score of
"+": Add a new score that is the sum of the previous
"D": Add a new score that is double the previous score.
"C": Invalidate and remove the previous score from the record.
Return the sum of all scores present on the record after applying all the operations.
Constraints:
operations.length
operations[i] is "C", "D", "+", or a string representing an integer in the range
For operation "+", there will always be at least
For operations "C" and "D", there will always be at least