This commit is contained in:
Gyubin Han
2025-02-19 14:09:55 +09:00
parent e3c6c8b32a
commit dede0dca01
36 changed files with 555 additions and 0 deletions

16
leetcode/13.py Normal file
View File

@@ -0,0 +1,16 @@
class Solution:
def romanToInt(self, s: str) -> int:
sv={'M':1000,'D':500,'C':100,'L':50,'X':10,'V':5,'I':1}
msv={'C':set(['D','M']),'X':set(['L','C']),'I':set(['V','X'])}
r=0
mc=''
for c in s:
r+=sv[c]
if mc in msv and c in msv[mc]:
r-=(sv[mc]*2)
if c in msv:
mc=c
else:
mc=''
return r