Algorithm - Baseball game save score - J ...

Algorithm - Baseball game save score - JavaScript

Oct 22, 2021

Algoritmos

Los Algoritmos son una serie de pasos lógicos a seguir para resolver un problema, tienen un inicio y un final, datos de entrada, procesos y datos de salida. Son la base para el desarrollo de software.

El proceso se lleva a cabo a través de preguntas lógicas y ciclos repetitivos para realizar cálculos aritméticos y entregar un resultado.

Exercise

You are keeping score for a baseball game with strange rules. The games consists of several rounds, where the scores of past rounds may effect future round's scores.

At the beginning of the game, you start with an empty score. You are given a list of strings ops, where ops[i] is the ith operation you must apply to the record and is one of following:

  •  An integer x - Record a new score of x

  • "+" - Record a new score that is the sum of the previous two scores. It is guaranteed there will always be two previous scores.

  • "D" - Record a new score that is double the previous score. It is guaranteed there will always be a previous score

  • "C" - Invalidate the previous score, removing it from the record. It is guaranteed there will always be a previous score.

Return the sum of all scores of the record.


Video

Suscríbete

Try the code in CodePen

Enjoy this post?

Buy YoLeo App a coffee

More from YoLeo App