刷题-Roman to Integer 缺python
来源:互联网 发布:软件新城物业公司 编辑:程序博客网 时间:2024/04/27 16:27
Given a roman numeral, convert it to an integer.
Input is guaranteed to be within the range from 1 to 3999.
public class Solution {
public int romanToInt(String s) {if (s.length()<1) return 0;
int result = 0;
int sub = luoma(s.charAt(0));
int last = sub;
for(int i = 1;i<s.length();i++){
char k = s.charAt(i);
int kk = luoma(k);
if (kk==last){
sub += kk;
}
else if(kk<last){
result += sub;
sub = kk;
}
else{
sub = kk - sub;
}
last = kk;
}
result = result +sub;
return result;
}
public int luoma(char x){
switch(x){
case 'I': return 1;
case 'V': return 5;
case 'X': return 10;
case 'L': return 50;
case 'C': return 100;
case 'D': return 500;
case 'M': return 1000;
default: return 0;
}
}
}
0 0
- 刷题-Roman to Integer 缺python
- Roman to Integer(python)
- 13. Roman to Integer python
- 12. Integer to Roman-python
- 【Leetcode】【python】Integer to Roman
- 【Leetcode】【python】Roman to Integer
- Leetcode-Roman to Integer-Python
- LeetCode 刷题: Roman to Integer
- 【LeetCode with Python】 Integer to Roman
- 【LeetCode with Python】 Roman to Integer
- 12. Integer to Roman Leetcode Python
- 13. Roman to Integer Leetcode Python
- leetcode(10),Roman to Integer(python)
- 13. Roman to Integer [easy] (Python)
- 【leetcode】Integer to Roman--python实现
- [leetcode:python]13.Roman to Integer
- [leetcode: Python]12. Integer to Roman
- 【LeetCode 13】Roman to Integer(Python)
- HTTP协议--概述 (一)
- SQL Server关于表的删除
- 【记录】Mac系统创建Cocos2dx3.2项目方法
- Alex 的 Hadoop 菜鸟教程: 第10课 Hive 安装和使用教程
- Linux下利用backtrace追踪函数调用堆栈以及定位段错误
- 刷题-Roman to Integer 缺python
- android下自定义字体的使用方法
- PHP经典项目案例-(一)博客管理系统1
- 监听中如何调用业务类
- 【COCOS2DX-LUA 脚本开发之一】在Cocos2dX游戏中使用Lua脚本进行游戏开发(基础篇)并介绍脚本在游戏中详细用途!
- 验证码基础
- C#: 通过html调用WinForm
- SQL Server中删除重复数据的几个方法
- apt-get常用命令