class Solution(object):
def romanToInt(self, s):
"""
:type s: str
:rtype: int
"""
numerals = { "M": 1000, "D": 500, "C": 100, "L": 50, "X": 10, "V": 5, "I": 1 } sums=0
s=s[::-1]
last=None for x in s:
if last and numerals[x] < last:
sums-=2*numerals[x]
sums+=numerals[x]
last=numerals[x]
return sums

@link http://www.cnblogs.com/zuoyuan/p/3779688.html

leetcode Roman to Integer python的更多相关文章

  1. LeetCode:Roman to Integer,Integer to Roman

    首先简单介绍一下罗马数字,一下摘自维基百科 罗马数字共有7个,即I(1).V(5).X(10).L(50).C(100).D(500)和M(1000).按照下述的规则可以表示任意正整数.需要注意的是罗 ...

  2. LeetCode: Roman to Integer 解题报告

    Roman to IntegerGiven a roman numeral, convert it to an integer. Input is guaranteed to be within th ...

  3. [LeetCode] Roman to Integer 罗马数字转化成整数

    Given a roman numeral, convert it to an integer. Input is guaranteed to be within the range from 1 t ...

  4. [Leetcode] Roman to Integer

    Given a roman numeral, convert it to an integer. Input is guaranteed to be within the range from 1 t ...

  5. [Leetcode] Roman to integer 罗马数字转成整数

    Given a roman numeral, convert it to an integer. Input is guaranteed to be within the range from 1 t ...

  6. [LeetCode][Python]Roman to Integer

    # -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com'https://oj.leetcode.com/problems/roman-t ...

  7. 【LeetCode】12. Integer to Roman 整数转罗马数字

    作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 个人公众号:负雪明烛 本文关键词:roman, 罗马数字,题解,leetcode, 力扣, ...

  8. 《LeetBook》leetcode题解(13):Roman to Integer[E]

    我现在在做一个叫<leetbook>的免费开源书项目,力求提供最易懂的中文思路,目前把解题思路都同步更新到gitbook上了,需要的同学可以去看看 书的地址:https://hk029.g ...

  9. LeetCode OJ:Integer to Roman(转换整数到罗马字符)

    Given an integer, convert it to a roman numeral. Input is guaranteed to be within the range from 1 t ...

随机推荐

  1. Mysql 计算时间间隔函数

    #计算两个时间的间隔 #计算间隔天数 select TIMESTAMPDIFF(day,'2014-06-01',date(now())) #计算间隔月数 select TIMESTAMPDIFF(m ...

  2. ADT Example

    Example Data Types: Integer, and Character Example (Integer Data Type) The integer data type can con ...

  3. T-SQL查询:三值逻辑

    1. 三值逻辑:TRUE / FALSE / UNKNOWN 2. 一个缺失的值(NULL)和另一个值进行比较,逻辑结果是UNKNOWN UNKOWN:NULL > 42 / NULL = NU ...

  4. unity读取Sqlite数据库

    using UnityEngine; using System.Collections; using Mono.Data.Sqlite; using System.Data; public enum ...

  5. C++ Primer 读书笔记: 第9章 顺序容器

    第9章 顺序容器 引: 顺序容器: vector 支持快速随机访问 list 支持快速插入/删除 deque 双端队列 顺序容器适配器: stack 后进先出栈 queue 先进先出队列 priori ...

  6. Android 数据库ORM框架GreenDao学习心得及使用总结<一>

    转: http://www.it165.net/pro/html/201401/9026.html 最近在对开发项目的性能进行优化.由于项目里涉及了大量的缓存处理和数据库运用,需要对数据库进行频繁的读 ...

  7. gets和fgets函数的区别

    1. gets与fgets gets函数原型:char*gets(char*buffer);//读取字符到数组:gets(str);str为数组名. gets函数功能:从键盘上输入字符,直至接受到换行 ...

  8. 将Python代码嵌入C++程序进行编写

    将Python代码嵌入C++程序进行编写的实例,python嵌入 把python嵌入的C++里面需要做一些步骤 安装python程序,这样才能使用python的头文件和库 在我们写的源文件中增加“Py ...

  9. libcurl编译

    下载: git://github.com/bagder/curl.git openssl: openssl编译   for linux or mingw:./buildconf./configure ...

  10. delphi中覆盖最大化消息(WM_GETMINMAXINFO)

    unit Unit1; interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs; ...