Solved LeetCode program · 485 of 1,000
#0682 · Baseball Game
Original English source
Keep a shared current as empty text. Keep a shared value of 0.
To read from spot (a whole number) with last (a whole number). If spot is more than last, return. The digit is the digit value of character spot of current. Set value to value times 10 plus digit. Read from spot plus 1 with last.
The operations is "5,2,C,D,+". The tokens is split operations by ",". The scores is an empty list of whole numbers. The depth is 0.
For each token in tokens.
Set current to a copy of token. The symbol is character 0 of current. If symbol is "C", remove the last item from scores, subtract 1 from depth. If symbol is "D", The doubled is item (depth minus 1) of scores times 2, Place doubled into scores, add 1 to depth. If symbol is "+", The joined is item (depth minus 1) of scores plus item (depth minus 2) of scores, Place joined into scores, add 1 to depth.
If symbol is between "0" and "9" or symbol is "-".
Set value to 0. The sign is 1. The start is 0. If symbol is "-", set sign to -1, set start to 1. The lastchar is the last position of current. Read from start with lastchar. Set value to value times sign. Place value into scores. Add 1 to depth.
The total is 0. For each score in scores, add score to total.
Show total.
Expected stdout
30