MCPcopy Create free account
hub / github.com/Ayush7614/Daily-Coding-DS-ALGO-Practice / romanToInt

Function romanToInt

Leetcode/RomanToInt.py:52–69  ·  view source on GitHub ↗
(s: str)

Source from the content-addressed store, hash-verified

50"""
51
52def romanToInt(s: str) -> int:
53 digits = {
54 'I': 1,
55 'V': 5,
56 'X': 10,
57 'L': 50,
58 'C': 100,
59 'D': 500,
60 'M': 1000
61 }
62 length = len(s)
63 v = digits[s[-1]];
64 for i in range(1, length):
65 if digits[s[i]] > digits[s[i - 1]]:
66 v -= digits[s[i - 1]];
67 else:
68 v += digits[s[i - 1]];
69 return v
70
71if __name__ == '__main__':
72 s=input()

Callers 1

RomanToInt.pyFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected