Problem13. Roman to Integer
来源:互联网 发布:淘宝评价怎么写好评 编辑:程序博客网 时间:2024/06/06 02:29
题目:
Given a roman numeral, convert it to an integer.
Input is guaranteed to be within the range from 1 to 3999.
class Solution { public int romanToInt(String s) { if(s==null||s.length()==0){return 0;} Map<Character,Integer> map=new HashMap<>(); 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); int len=s.length(); int result=map.get(s.charAt(len-1)); int pivort=result; for(int i=len-2;i>=0;i--){ int curr=map.get(s.charAt(i)); if(curr>=pivort){ result+=curr; }else{ result-=curr; } pivort=curr; } return result; }}
阅读全文
0 0
- Problem13. Roman to Integer
- leetcode problem13 Rome to Integer
- 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
- Integer to Roman and Roman to Integer
- LeetCode Integer to Roman & Roman to Integer
- Roman to Integer/Integer to Roman
- leetcode - roman to integer & integer to roman
- "Roman to Integer" and "Integer to Roman"
- Roman to Integer &&Integer to Roman
- Roman to Integer and Integer to Roman
- Roman to Integer/Integer to Roman
- LeetCode:Roman to Integer
- LeetCode: Integer to Roman
- iOS 项目的文件 获取路径为nil
- 寻路算法
- RPC远程过程调用之我的理解(附带项目希望有人交流)
- 错误:Underlying DBMS error[ORA-01653]:unable to extend table SDE……*
- mybatis打印sql日志
- Problem13. Roman to Integer
- Cocos2d-x v3.x官方文档】序列帧动画
- 常用页面提交方式 | 防止重复提交
- extern作用详解
- 使用的插件集合
- 数组的使用
- 模仿米家有品网页4
- Git学习文档
- CentOS7.4安装软件出现错误:/lib/ld-linux.so.2: bad ELF interpreter 解决