[LeetCode] Roman to Integer 파이썬 (dict, stack, deque)
from collections import deque class Solution: def romanToInt(self, s: str) -> int: symbol = {"IV":4, "IX":9, "XL":40, "XC":90, "CD":400, "CM":900} roman = {"I":1,"V":5,"X":10,"L":50,"C":100,"D":500, "M":1000, "IV":4, "IX":9, "XL":40, "XC":90, "CD":400, "CM":900} stack = deque() stack.append((s[0],0)) for i in range(1, len(s)): pattern = stack[-1][0]+s[i] if pattern in symbol: stack.pop() stack.a..
2021. 3. 26.