13. Roman to Integer
来源:互联网 发布:怎么样提高淘宝转化率 编辑:程序博客网 时间:2024/06/03 13:20
13. Roman to Integer
Leetcode link for this question
Discription:
Given a roman numeral, convert it to an integer.
Input is guaranteed to be within the range from 1 to 3999.
Analyze:
Code 1:
class Solution(object): def romanToInt(self, s): """ :type s: str :rtype: int """ dic={'I':1,'II':2,'III':3,'V':5,'X':10,'L':50,'C':100,'D':500,'M':1000,'v':5*1000,'x':10*1000,'l':50*1000,'c':100*1000,'d':500*1000,'m':1000*1000} li=s ln=[] for i in li: if ln and dic[i]>ln[-1]: ln[-1]=-1*ln[-1] ln.append(dic[i]) return sum(ln)
Submission Result:
Status: Accepted
Runtime: 176 ms
Ranking: beats 68.85%
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
- ASP.NET常用的正则表达式
- 关于java部分知识点的总结(三)
- ReactNative学习小结
- window 10 下为SQL Server 关闭防火墙
- 深入理解Java:注解(Annotation)基本概念
- 13. Roman to Integer
- 如何使用Android Studio把自己的Android library分享到jCenter和Maven Central
- 架构实践
- commons-lang中常用方法
- 《剑指offer》第31题:连续子数组的最大和
- java的接口回调机制详解
- Android导出Kml
- JAVA 自动化测试问题云集
- 关于新开岭电站球阀漏油问题处理过程的总结