Skip to content

Commit

Permalink
solution(python): 13. Roman to Integer
Browse files Browse the repository at this point in the history
13. Roman to Integer
  • Loading branch information
godkingjay authored Oct 10, 2023
2 parents 1c86d9e + 1e2d3d8 commit 407f0a0
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions Easy/13. Roman to Integer/Solution.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
roman = {'I':1,'V':5,'X':10,'L':50,'C':100,'D':500,'M':1000}
class Solution:
def romanToInt(self, S: str) -> int:
summ= 0
for i in range(len(S)-1,-1,-1):
num = roman[S[i]]
if 3*num < summ:
summ = summ-num
else:
summ = summ+num
return summ

0 comments on commit 407f0a0

Please sign in to comment.