leetcode Roman to Integer python
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的更多相关文章
- LeetCode:Roman to Integer,Integer to Roman
首先简单介绍一下罗马数字,一下摘自维基百科 罗马数字共有7个,即I(1).V(5).X(10).L(50).C(100).D(500)和M(1000).按照下述的规则可以表示任意正整数.需要注意的是罗 ...
- LeetCode: Roman to Integer 解题报告
Roman to IntegerGiven a roman numeral, convert it to an integer. Input is guaranteed to be within th ...
- [LeetCode] Roman to Integer 罗马数字转化成整数
Given a roman numeral, convert it to an integer. Input is guaranteed to be within the range from 1 t ...
- [Leetcode] Roman to Integer
Given a roman numeral, convert it to an integer. Input is guaranteed to be within the range from 1 t ...
- [Leetcode] Roman to integer 罗马数字转成整数
Given a roman numeral, convert it to an integer. Input is guaranteed to be within the range from 1 t ...
- [LeetCode][Python]Roman to Integer
# -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com'https://oj.leetcode.com/problems/roman-t ...
- 【LeetCode】12. Integer to Roman 整数转罗马数字
作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 个人公众号:负雪明烛 本文关键词:roman, 罗马数字,题解,leetcode, 力扣, ...
- 《LeetBook》leetcode题解(13):Roman to Integer[E]
我现在在做一个叫<leetbook>的免费开源书项目,力求提供最易懂的中文思路,目前把解题思路都同步更新到gitbook上了,需要的同学可以去看看 书的地址:https://hk029.g ...
- 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 ...
随机推荐
- Effective C++ 条款18
让接口easy被正确使用,不easy被误用 如题目,我们自己的程序接口是面向用户的,程序的目的不可是解决这个问题,并且要让用户easy使用.所以.必须保证我们的程序接口具有非常强的鲁棒性. 怎么保证接 ...
- 一个tabBarController管理多个Storyboard
随着项目的业务逻辑越来越复杂,随着项目越来越大,那么我们Storybard中得控制器就越来越多, 就越来越难以维护.然而使用Storyborad又能更方便的帮助我们做屏幕适配(PS:尤其在6.6+出来 ...
- Excel中公式的绝对引用和相对引用单元格
在Excel的表格中,非常常用的就是公式里的绝对引用和相对引用了,具体情况请看下列表格吧. 步骤1 打开做好的excel表格.公式中的相对单元格引用是基于包含公式和单元格引用的单元格的相对位置,若公式 ...
- 第四课 Grid Control实验 GC Agent安装(第一台机器部署) 及卸载
3.GC Agent安装(第一台机器部署) 安装Agent 拷贝agent,现在ocm2机器上查找agent.linux 查找文件的方法: find ./ -name agent*linux 把ag ...
- 关于FND_PROFILE与FND_GLOBLE[Z]
fnd_global package可以取得一些關於當前login in用戶的信息 fnd_concurrent_requests functions select FND_PROFILE.VAL ...
- 【codevs】2292图灵机游戏
题 Shadow最近知道了图灵机是什么(Shadow:就是一行格子和一个机器头移来移去的呗!),于是他突发奇想,创造了一个新游戏——“图灵机游戏”(Shadow:好听吧?). 游戏规则如下: 在一条长 ...
- Linux 学习之防火墙配置
1.安装iptables防火墙 yum install iptables 2. 清除已有的iptables规则 iptables -F iptables -X iptables -Z 3.显 ...
- OSC本地库推送到远程库
1.新建远程库: 例如:http://git.oschina.net/intval/learngit 2.本地生成ssh密钥 ssh-keygen -t rsa -C "intval@163 ...
- javascript 中字符串之比较
<script type="text/javascript"> var string1="apple"; var string2="Ban ...
- 关于Thinkphp3.2版本的分页问题
最近公司官网改版,需要把旧的thinkphp版本换到现在最新的3.2去,因此,就开展了一系列的升级工作..在修改命名空间的同时,发现Page分页类能正常运行了,但是分页的链接却是错误的,例如在Admi ...