13.Roman to Integer
来源:互联网 发布:美丽港发型设计软件 编辑:程序博客网 时间:2024/05/01 17:52
给你一个罗马数字,把它转化成整数
给的数字的范围在1-3999
class Solution(object):
def romanToInt(self, s):
"""
:type s: str
:rtype: int
"""
dict = {'I':1,'V':5,'X':10,'L':50,'C':100,'D':500,'M':1000}
num = 0
for i in range(len(s[:-1])):
if dict[s[i]] <dict[s[i+1]]:
num -= dict[s[i]]
else:
num += dict[s[i]]
return num + dict[s[-1]]
0 0
- 13. Roman to Integer
- 13.Roman to Integer
- 13. Roman to Integer
- 13.Roman to Integer
- 13. Roman to Integer
- 13. Roman to Integer
- 13. Roman to Integer
- 13. Roman to Integer
- 13. Roman to Integer
- 13. Roman to Integer
- 13. Roman to Integer
- 13. Roman to Integer
- 13. Roman to Integer
- 13. Roman to Integer
- 13. Roman to Integer
- 13. Roman to Integer
- 13. Roman to Integer
- 13. Roman to Integer
- JavaScript(JS)
- UVA 1632 区间DP
- gradle升级到2.3,出现的编译错误
- 机器学习笔记(七)Boost算法(GDBT,AdaBoost,XGBoost)原理及实践
- ubuntu 16.04 启用root用户方法(亲测可行)
- 13.Roman to Integer
- go语言比较常用的用法
- Power of Four
- mpu6050姿态解算与卡尔曼滤波(2)卡尔曼滤波
- 【OpenGL】GLUT函数说明
- c++实验2-分段函数求值
- UVA 10934 Dropping water balloons (动规)
- javaEE之SSH框架的底层机制及原理
- 提交github操作