13. Roman to Integer
来源:互联网 发布:淘宝北京新大陆可靠吗 编辑:程序博客网 时间:2024/06/11 21:57
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) { int res = 0;//char[] str = s.toCharArray();String[] strs = new String[s.length()];for(int i=0;i<s.length();i++){ strs[i] = s.substring(i,i+1);}HashMap<String,Integer> map = new HashMap<String,Integer>();map.put("I", 1);map.put("V", 5);map.put("X", 10);map.put("L", 50);map.put("C", 100);map.put("D", 500);map.put("M", 1000);String max = "I";for(int i=s.length()-1;i>=0;--i){if(map.get(strs[i])>=map.get(max)){max = strs[i];res += map.get(strs[i]);}else{res -= map.get(strs[i]);}} return res; }}
0 0
- 13. Roman to Integer
- 13.Roman to Integer
- 13. Roman to Integer
- 13.Roman to Integer
- 13. Roman to Integer
- 13. Roman to Integer
- 13. Roman to Integer
- 13. Roman to Integer
- 13. Roman to Integer
- 13. Roman to Integer
- 13. Roman to Integer
- 13. Roman to Integer
- 13. Roman to Integer
- 13. Roman to Integer
- 13. Roman to Integer
- 13. Roman to Integer
- 13. Roman to Integer
- 13. Roman to Integer
- 并查集_森林_含秩的判断和路径优化
- 表的连接查询
- 为什么空类占一个字节?
- ORA-28000 用户被锁解锁
- 了解Zones
- 13. Roman to Integer
- CDH5.7/5.8离线安装-使用CM5,基于CentOS 6.7
- 博客搬迁
- Linux命令-find
- 机器学习经典图
- 【poj 3150】Cellular Automaton 矩阵
- 19. Remove Nth Node From End of List
- 沉浸式状态栏
- LambdaMART的源码分析:一(MART:回归树)