| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 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
- 컴퓨터의 구조
- 715. Range Module
- Regular Expression
- concurrency
- 30. Substring with Concatenation of All Words
- attribute
- Python Implementation
- Protocol
- LeetCode
- Substring with Concatenation of All Words
- 밴픽
- Python Code
- DWG
- Class
- shiba
- 109. Convert Sorted List to Binary Search Tree
- 시바견
- 315. Count of Smaller Numbers After Self
- 파이썬
- t1
- 43. Multiply Strings
- iterator
- 운영체제
- 프로그래머스
- kaggle
- Decorator
- Convert Sorted List to Binary Search Tree
- data science
- Python
- Generator
Archives
- Today
- Total
Scribbling
LeetCode: 150. Evaluate Reverse Polish Notation 본문
Computer Science/Coding Test
LeetCode: 150. Evaluate Reverse Polish Notation
focalpoint 2021. 11. 26. 11:36stack을 사용
class Solution:
def evalRPN(self, tokens: List[str]) -> int:
stack = []
predefined_tokens = ['+', '-', '*', '/']
operations = [lambda x, y : x + y, lambda x, y : x - y,
lambda x, y : x * y, lambda x, y : int(x / y)]
for token in tokens:
if token in predefined_tokens:
num2 = stack.pop()
num1 = stack.pop()
idx = predefined_tokens.index(token)
stack.append(operations[idx](num1, num2))
else:
stack.append(int(token))
return stack[0]'Computer Science > Coding Test' 카테고리의 다른 글
| LeetCode: 152. Maximum Product Subarray (0) | 2021.11.29 |
|---|---|
| LeetCode: 134. Gas Station (0) | 2021.11.26 |
| LeetCode: 238. Product of Array Except Self (0) | 2021.11.25 |
| LeetCode: 1329. Sort the Matrix Diagonally (0) | 2021.11.24 |
| LeetCode: 1466. Reorder Routes to Make All Paths Lead to the City Zero (0) | 2021.11.23 |