13. Roman to Integer
2016-07-19 16:00
337 查看
13. Roman to Integer
Leetcode link for this questionDiscription:
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: AcceptedRuntime: 176 ms
Ranking: beats 68.85%
相关文章推荐
- 深入理解Java:注解(Annotation)基本概念
- window 10 下为SQL Server 关闭防火墙
- ansible 动态生成Inventory
- Android定制出厂默认输入法(其他设置类似)
- MarkdownPad2.5 注册码
- Java StringBuffer和StringBuilder类
- AFNetworking 3.0 源码解读(一)之 AFNetworkReachabilityManager
- 【NYOJ】[845]无主之地1
- 初识 Android Studio
- EventBus使用详解(一)——初步使用EventBus
- Android Sensor传感器系统架构初探
- 采用CreateThread()创建多线程程序
- NYOJ_119_士兵杀敌(三)
- 阅读Sofia-SIP源码 - su模块 - su.h
- 带返回值的线程:Callable、Future和FutureTask
- 文章标题
- dijkstra + heap 优化
- 深度链接、延迟深度链接、App Links以及关于LinkedME实现深度链接的原理解析
- 1014. 福尔摩斯的约会 (20)--做题纪录
- 教你一分钟实现动态模糊效果