Tap here to switch tabs
Problem
Submissions

Problem: Baseball Game

Try to solve the Baseball Game problem.

Statement

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 xx to the record.

  • "+": Add a new score that is the sum of the previous 22 scores.

  • "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:

  • 1≤1 \leq operations.length ≤1000\leq 1000

  • operations[i] is "C", "D", "+", or a string representing an integer in the range [−3imes104,3imes104][-3 imes 10^4, 3 imes 10^4]

  • For operation "+", there will always be at least 22 previous scores on the record

  • For operations "C" and "D", there will always be at least 11 previous score on the record

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Baseball Game

Try to solve the Baseball Game problem.

Statement

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 xx to the record.

  • "+": Add a new score that is the sum of the previous 22 scores.

  • "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:

  • 1≤1 \leq operations.length ≤1000\leq 1000

  • operations[i] is "C", "D", "+", or a string representing an integer in the range [−3imes104,3imes104][-3 imes 10^4, 3 imes 10^4]

  • For operation "+", there will always be at least 22 previous scores on the record

  • For operations "C" and "D", there will always be at least 11 previous score on the record