Problem Solving
63. Baseball Game
굥깡
2023. 1. 9. 02:51
728x90
https://leetcode.com/problems/baseball-game/
Baseball Game - LeetCode
Baseball Game - You are keeping the scores for a baseball game with strange rules. At the beginning of the game, you start with an empty record. You are given a list of strings operations, where operations[i] is the ith operation you must apply to the reco
leetcode.com
특정 char를 입력받으면 특정 연산을 수행하고, 최종적으로 모든 수를 합하는 문제
class Solution:
def calPoints(self, operations: list[str]) -> int:
score = []
for i in operations:
if i == "+":
score.append(score[-1] + score[-2])
elif i == "D":
score.append(score[-1] * 2)
elif i == "C":
score.pop()
else:
score.append(int(i))
print(score)
return sum(score)
계속 나오는 유형이라 푸는 것보다 이해하는 게 더 걸렸음