Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit55100e4

Browse files
add 1 code
1 parente006f31 commit55100e4

File tree

2 files changed

+72
-45
lines changed

2 files changed

+72
-45
lines changed

‎.idea/workspace.xml

Lines changed: 50 additions & 45 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎leetcode/13. Roman to Integer.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
classSolution(object):
10+
defromanToInt(self,s):
11+
romanDict= {'M':1000,'D':500,'C':100,'L':50,'X':10,'V':5,'I':1}
12+
res,p=0,'I'
13+
forchins[::-1]:
14+
ifromanDict[ch]<romanDict[p]:
15+
res=res-romanDict[ch]
16+
else:
17+
res=res+romanDict[ch]
18+
p=ch
19+
returnres
20+
21+
s=Solution()
22+
print((s.romanToInt("IX")))

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp