13. Roman to Integer
2016-07-26 19:34
323 查看
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%
相关文章推荐
- UVALive - 2701 Find The Multiple
- 阅一道简单程序,了解多线程编程;
- drop table中cascade的含义及用法
- 7. Reverse Integer
- Dynamics CRM 2016 修改服务器名字
- [SCU4437] Carries [2015 Sichuan Province Contest Final B]
- 6. ZigZag Conversion
- Linux-(C)多线程学习(入门)
- 弹性ListView
- 使用Android Studio查找文件中含有中文字符串位置(正则表达式)
- 1. Two Sum
- Android SyncAdapter同步实践
- 小明的求助
- OI总结(垃圾排版就忽略了吧)
- HDU 5761 Rower Bo
- 如何灵活运用转义字符还有玩转常量0726
- 通过KEPWARE ODBC DRIVER和ADVANCED TAG 实现数据库和PLC的双向通信
- 套题 bestcoder 84
- UVA 10603 Fill【BFS】
- ORACLE中Drop table cascade constraints之后果.