Skip to content

Commit 115eeb7

Browse files
authored
Update baseball-game.py
1 parent c732bea commit 115eeb7

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

Python/baseball-game.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,49 @@
11
# Time: O(n)
22
# Space: O(n)
33

4+
# You're now a baseball game point recorder.
5+
# Given a list of strings, each string can be one of the 4 following types:
6+
#
7+
# 1. Integer (one round's score): Directly represents the number of points you get in this round.
8+
# 2. "+" (one round's score): Represents that the points you get in this round are
9+
# the sum of the last two valid round's points.
10+
# 3. "D" (one round's score): Represents that the points you get in this round are
11+
# the doubled data of the last valid round's points.
12+
# 4. "C" (an operation, which isn't a round's score): Represents the last valid round's points
13+
# you get were invalid and should be removed.
14+
#
15+
# Each round's operation is permanent and could have an impact on the round before and the round after.
16+
# You need to return the sum of the points you could get in all the rounds.
17+
#
18+
# Example 1:
19+
#
20+
# Input: ["5","2","C","D","+"]
21+
# Output: 30
22+
# Explanation:
23+
# Round 1: You could get 5 points. The sum is: 5.
24+
# Round 2: You could get 2 points. The sum is: 7.
25+
# Operation 1: The round 2's data was invalid. The sum is: 5.
26+
# Round 3: You could get 10 points (the round 2's data has been removed). The sum is: 15.
27+
# Round 4: You could get 5 + 10 = 15 points. The sum is: 30.
28+
#
29+
# Example 2:
30+
#
31+
# Input: ["5","-2","4","C","D","9","+","+"]
32+
# Output: 27
33+
# Explanation:
34+
# Round 1: You could get 5 points. The sum is: 5.
35+
# Round 2: You could get -2 points. The sum is: 3.
36+
# Round 3: You could get 4 points. The sum is: 7.
37+
# Operation 1: The round 3's data is invalid. The sum is: 3.
38+
# Round 4: You could get -4 points (the round 3's data has been removed). The sum is: -1.
39+
# Round 5: You could get 9 points. The sum is: 8.
40+
# Round 6: You could get -4 + 9 = 5 points. The sum is 13.
41+
# Round 7: You could get 9 + 5 = 14 points. The sum is 27.
42+
#
43+
# Note:
44+
# The size of the input list will be between 1 and 1000.
45+
# Every integer represented in the list will be between -30000 and 30000.
46+
447
class Solution(object):
548
def calPoints(self, ops):
649
"""

0 commit comments

Comments
 (0)