# [LeetCode]#682. Baseball Game

1. An integer `x` - Record a new score of `x`.
2. `"+"` - Record a new score that is the sum of the previous two scores. It is guaranteed there will always be two previous scores.
3. `"D"` - Record a new score that is double the previous score. It is guaranteed there will always be a previous score.
4. `"C"` - Invalidate the previous score, removing it from the record. It is guaranteed there will always be a previous score.
`Input: ops = ["5","2","C","D","+"]Output: 30Explanation:"5" - Add 5 to the record, record is now [5]."2" - Add 2 to the record, record is now [5, 2]."C" - Invalidate and remove the previous score, record is now [5]."D" - Add 2 * 5 = 10 to the record, record is now [5, 10]."+" - Add 5 + 10 = 15 to the record, record is now [5, 10, 15].The total sum is 5 + 10 + 15 = 30.`
1. if i is number, add it.
2. if i is C, remove last one.
3. if i is D, add ops[i-1]x2
4. if i is “+”, add ops[i-1] + ops[i-2]
5. Return Summary
`class Solution:    def calPoints(self, ops):        ans=[]                for i in ops:            if i=="C":                ans.pop()            elif i=="D":                ans.append(ans[-1]*2)            elif i=="+":                ans.append(ans[-1]+ans[-2])            else:                ans.append(int(i))        return sum(ans)`

## More from Fatboy Slim

Interesting in any computer science.

Love podcasts or audiobooks? Learn on the go with our new app.

## Fatboy Slim

Interesting in any computer science.