We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent e006f31 commit 55100e4Copy full SHA for 55100e4
2 files changed
.idea/workspace.xml
leetcode/13. Roman to Integer.py
@@ -0,0 +1,22 @@
1
+# -*- coding:utf-8 -*-
2
+'''
3
+Given a roman numeral, convert it to an integer.
4
+
5
+Input is guaranteed to be within the range from 1 to 3999.
6
7
8
9
+class Solution(object):
10
+ def romanToInt(self, s):
11
+ romanDict = {'M':1000, 'D':500, 'C':100, 'L':50, 'X':10, 'V':5, 'I':1}
12
+ res, p = 0, 'I'
13
+ for ch in s[::-1]:
14
+ if romanDict[ch] < romanDict[p]:
15
+ res = res - romanDict[ch]
16
+ else:
17
+ res = res + romanDict[ch]
18
+ p = ch
19
+ return res
20
21
+s = Solution()
22
+print((s.romanToInt("IX")))
0 commit comments