Roman to Int
来源:互联网 发布:linux卸载nagios 编辑:程序博客网 时间:2024/05/28 18:42
Given a roman numeral, convert it to an integer.
Input is guaranteed to be within the range from 1 to 3999.
public int romanToInt(String s) { Map roman = new HashMap(); int result = 0; roman.put('I',1); roman.put('V',5); roman.put('X',10); roman.put('L',50); roman.put('C',100); roman.put('D',500); roman.put('M',1000); for(int i=s.length()-1;i>=0;i--){ if(i==s.length()-1){ result=roman.get(s.charAt(i)); continue; } if(roman.get(s.charAt(i)) >= roman.get(s.charAt(i+1))) result+=roman.get(s.charAt(i)); else result-=roman.get(s.charAt(i)); } return result; }
0 0
- Int to Roman And Roman to Int
- Int to Roman
- Roman to Int
- Roman to Int
- Int to Roman
- Int to Roman
- ROMAN TO INT
- Leetcode-12 int to Roman
- leetcode (12) - INT TO ROMAN
- leetcode (13) - ROMAN TO INT
- LeetCode算法题之int to Roman
- 13. Roman to Integer (罗马数字转int)
- Integer to Roman & Roman to Integer
- Integer to Roman & Roman to Integer
- LeetCode Roman to Integer && Integer to Roman
- 【leetcode】Roman to Integer | Integer to Roman
- Leetcode - "Roman to Integer" & "Integer to Roman"
- LeetCode:Roman to Integer,Integer to Roman
- JUnit4.11和hamcrest-core-1.3 搭建自己的测试环境(非eclipse内置Junit)
- Java读取注册表总结之com.ice.jni.registry
- ocp 1Z0-051 141-175题解析
- 用Python创建gzip压缩文件
- HDU5144 NPY and shot
- Roman to Int
- 50电话拦截
- 实习篇---第十八天
- 知识总结十一点
- 微软内部泄露的Windows XP的KEY和无限次激活码
- python利用gzip压缩解压缩StringIO
- python 字典的get方法
- 交叉编译链简单介绍
- Linux系统文件系统的结构层次