# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3.8.3 ('base')
#     language: python
#     name: python3
# ---

# Example 1:
#
# Input: s = "III"\
# Output: 3\
# Explanation: III = 3.
#
# Example 2:
#
# Input: s = "LVIII"\
# Output: 58\
# Explanation: L = 50, V= 5, III = 3.
#
# Example 3:
#
# Input: s = "MCMXCIV"\
# Output: 1994\
# Explanation: M = 1000, CM = 900, XC = 90 and IV = 4.

class Solution:
    def romanToInt(self, S: str) -> int:
        roman = {'I':1, 'V':5, 'X':10, 'L':50, 'C':100, 'D':500, 'M':1000}
        s = [i for i in S]

        tot = 0
        for i in range(len(s)):
            if i + 1 < len(s) and roman[s[i]] < roman[s[i + 1]]:
                tot -= roman[s[i]]
            else:
                tot += roman[s[i]]
            
        return tot


# +
x = Solution()

x.romanToInt('III')

StarcoderdataJupyterScriptsDedupFiltered