Baseball Game

Easy

Topics
StackSimulation

You are given operations as a space-separated string s. Each token is an integer (record it), "+" (sum of last two), "D" (double last), or "C" (invalidate last). Return the total sum of the record.

Example 1

Input:  s = "5 2 C D +"
Output: 30

Example 2

Input:  s = "5 -2 4 C D 9 + +"
Output: 27

Constraints

  • 1 <= number of operations <= 1000
  • Operations are valid when applied.
Run ⌘' · Submit ⌘⏎