Problem Solving/LeetCode
Today's Challenge
fabichoi
2022. 12. 17. 23:45
https://leetcode.com/problems/evaluate-reverse-polish-notation/
Evaluate Reverse Polish Notation - LeetCode
Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.
leetcode.com
스택을 이용하는거 까진 알겠는데
생각보다 간단했다는건 몰랐음 =_=;
class Solution:
def evalRPN(self, tokens: List[str]) -> int:
st = []
for token in tokens:
if token in ['*', '/', '-', '+']:
r = st.pop()
l = st.pop()
st.append(str(int(eval(l+token+r))))
else:
st.append(token)
return int(st[-1])
반응형