Skip to content

Commit 7ff12d9

Browse files
backendbuilderdevAjeethundalPankajjajra
committed
Roman to integer problem solution
Co-Authored-By: Ajeet hundal <[email protected]> Co-Authored-By: Pankaj Jajra <[email protected]>
1 parent 8c6d454 commit 7ff12d9

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

013_Roman_To_Integer.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
class Solution:
2+
# @param {string} s
3+
# @return {integer}
4+
def romanToInt(self, s):
5+
roman = {'M': 1000,'D': 500 ,'C': 100,'L': 50,'X': 10,'V': 5,'I': 1}
6+
7+
result = 0
8+
for i in range(len(s)-1):
9+
if roman[s[i]]<roman[s[i+1]]:
10+
result-=roman[s[i]]
11+
else:
12+
result+=roman[s[i]]
13+
else:
14+
result+=roman[s[-1]]
15+
16+
return result
17+

0 commit comments

Comments
 (0)