All problems
1044EasyArrayStackSimulation

Tallying a Round With Corrections

Tracked in this browser only
Write code

Trains the technique from

LeetCode 682Baseball Game

This is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.

Same function shape, different story and different numbers.

A scorer's sheet reads entries, worked through in order. Each entry is one of the following:

  • a whole number written as text: record that score;
  • "+": record a score equal to the last two recorded scores added together;
  • "D": record a score equal to twice the last recorded score;
  • "C": strike out the last recorded score, as though it had never been recorded.

Return all the recorded scores added together once the whole sheet has been worked through.

Every "+" has at least two scores already recorded, and every "D" and "C" at least one.

Examples

Example 1

Input
entries = ["3", "D", "D"]
Output
21

Three is recorded, then twice it, six, then twice that, twelve. Three, six and twelve add to twenty-one.

Example 2

Input
entries = ["-5", "D", "+"]
Output
-30

Minus five is recorded, then twice it, minus ten, then those two added, minus fifteen. The three together come to minus thirty.

Example 3

Input
entries = ["10"]
Output
10

One entry and one recorded score, so the total is that score.

Constraints

  • 1 <= entries.length <= 1000
  • Each entry is "C", "D", "+", or a whole number written as text between -30000 and 30000.

The signature

The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.

Python
def cal_points(entries: list[str]) -> int:
Java
public int calPoints(String[] entries)
September 7
Apply