Limited time: AI code review, hints, mock interviews, whiteboard analysis, and all Pro features are unlocked. Enroll

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 ⌘⏎
SensAI SensAI
Beta
Listening...
Tap mic to stop voice mode

Unlock AI Features

One click to activate - no payment, no credit card. Just sign in and you're in.

AI code review and hints
SensAI chat assistant
AI mock interviews
Whiteboard analysis
100% free during early access