일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
Tags
- stratascratch
- Python3
- 리트코드
- GenerativeAI
- tree
- LeetCode
- 파이썬기초100제
- codeup
- heap
- two-pointer
- 파이썬
- dfs
- 알고리즘
- 자연어처리
- 니트코드
- Python
- 릿코드
- Stack
- SQL
- 파이썬알고리즘
- 생성형AI
- medium
- 코드업
- GenAI
- sql코테
- 투포인터
- nlp
- gcp
- slidingwindow
- 슬라이딩윈도우
Archives
- Today
- Total
Tech for good
[Leetcode/Stack] 682. Baseball Game 본문
🌷 Stack
- push(): 데이터를 넣는다/추가한다 (+) / Adds x to the top of the stack
- pop(): 데이터를 꺼낸다/뺀다 (-) / Removes and returns the top item
- append(): Add an element x to the end of a list
class Solution:
def calPoints(self, operations: List[str]) -> int:
stack = []
for op in operations:
if op == "C":
stack.pop()
elif op == "D":
stack.append(2 * stack[-1])
elif op == "+":
stack.append(stack[-1] + stack[-2])
else:
stack.append(int(op))
return sum(stack)
'IT > Computer Science' 카테고리의 다른 글
[Leetcode/Stack] 1614. Maximum Nesting Depth of the Parentheses (0) | 2025.04.21 |
---|---|
[Leetcode/Stack,Tree] 897. Increasing Order Search Tree (0) | 2025.04.16 |
[Leetcode/Stack] 234. Palindrome Linked List (0) | 2025.04.14 |
[Leetcode/Stack] 496. Next Greater Element I (0) | 2025.04.14 |
[Leetcode/Heap] 1438. Longest Continuous Subarray With Absolute Diff Less Than or Equal to Limit (0) | 2025.04.11 |