-
63. Baseball GameProblem Solving 2023. 1. 9. 02:51728x90
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)
계속 나오는 유형이라 푸는 것보다 이해하는 게 더 걸렸음
'Problem Solving' 카테고리의 다른 글
66. Next Greater Element I (0) 2023.01.09 65. Reverse Linked List (0) 2023.01.09 62. 2016년 (0) 2023.01.09 61. Add Binary (0) 2023.01.09 60. Height Checker (0) 2023.01.09