LeetCode 算法刷题(13)
来源:互联网 发布:安防网络系统 编辑:程序博客网 时间:2024/06/07 16:15
13. Roman to Integer
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) { int result = 0; int[] nums = {1000,500,100,50,10,5,1}; String chars = "MDCLXVI"; for(int i=0; i<s.length(); i++){ int index = chars.indexOf(s.charAt(i)); int nextindex = 0; if(i==s.length()-1){ nextindex = chars.indexOf(s.charAt(i)); }else{ nextindex = chars.indexOf(s.charAt(i+1)); } int thisInt = nums[index]; if(nums[index]<nums[nextindex]){ thisInt = nums[nextindex]-nums[index]; i++; } result = result+thisInt; } return result; }
0 0
- LeetCode 算法刷题(13)
- leetcode算法刷题
- leetcode算法刷题
- Leetcode 算法题13
- LeetCode 算法刷题(3)
- LeetCode 算法刷题(373)
- LeetCode 算法刷题(4)
- LeetCode 算法刷题(7)
- LeetCode 算法刷题(6)
- LeetCode 算法刷题(5)
- LeetCode 算法刷题(9)
- LeetCode 算法刷题(10)
- LeetCode 算法刷题(12)
- leetcode算法刷题-持续更新
- Leetcode sql算法题
- LeetCode | HouseRobber 算法题
- leetcode算法第二题
- LeetCode算法题典
- Hibernate缓存机制详解
- 使用Html.BeginForm("ActionName", "ControllerName", FormMethod.Post, new { id = "formInfo" })提交数据的问题
- CSS 伪类及伪元素用法详解
- Android 基础知识
- Java 空判断
- LeetCode 算法刷题(13)
- HDU6020 MG loves apple
- Unity3D作业六项目一——优化打飞碟游戏
- eclipse启动项目报错: java.lang.OutOfMemoryError:PermGen space
- 正则表达式解析
- Unsupported major.minor version 52.0
- Android基于HLS和RTMP协议的第三方SDK选择
- swift中关于
- python string的编码方式