Skip to content

Commit 6ec7bbc

Browse files
authored
Initial File
Roman Numerals to Integer
1 parent 2eb3e24 commit 6ec7bbc

1 file changed

Lines changed: 36 additions & 0 deletions

File tree

romantointeger

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
def romantointeger(A):
2+
result=0
3+
i=0
4+
while(i<len(A)):
5+
curr=value(A[i])
6+
if(i+1<len(A)):
7+
next=value(A[i+1])
8+
if(curr>=next):
9+
result=result+curr
10+
i=i+1
11+
else:
12+
result=result+(next-curr)
13+
i=i+2
14+
else:
15+
result=result+curr
16+
i=i+1
17+
return result
18+
19+
20+
21+
def value(A):
22+
if(A=='I'):
23+
return 1
24+
if(A=='V'):
25+
return 5
26+
if(A=='X'):
27+
return 10
28+
if(A=='L'):
29+
return 50
30+
if(A=='C'):
31+
return 100
32+
if(A=='D'):
33+
return 500
34+
if(A=='M'):
35+
return 1000
36+

0 commit comments

Comments
 (0)