LeetCode 13 Roman to Integer
来源:互联网 发布:大学生就业压力知乎 编辑:程序博客网 时间:2024/06/06 19:38
Given a roman numeral, convert it to an integer.
Input is guaranteed to be within the range from 1 to 3999.
小数字在大数字前面表示的数是用大数字减去小数字,如 IV=4;
小数字在大数字后面表示的数是用大数字加上小数字,如VII=7;
public int romanToInt(String s) {HashMap<Character, Integer> map = new HashMap<Character, 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);int value = map.get(s.charAt(0));for (int i = 1; i < s.length(); i++) {if (map.get(s.charAt(i)) > map.get(s.charAt(i - 1))) {value = value + map.get(s.charAt(i)) - 2 * map.get(s.charAt(i - 1));} else {value = value + map.get(s.charAt(i));}}return value;}
0 0
- leetcode-13:Roman to Integer
- leetcode 13 Roman to Integer
- Leetcode【13】:Roman to Integer
- [leetcode 13] Roman to Integer
- [Leetcode] 13 - Roman to Integer
- LeetCode | #13 Roman to Integer
- leetcode.13---------Roman to Integer
- leetCode #13 Roman to Integer
- leetcode-13 Roman to Integer
- leetcode 13 Roman to Integer
- LeetCode 13 Roman to Integer
- LeetCode 13 - Roman to Integer
- leetcode 13 -- Roman to Integer
- LeetCode 13:"Roman to Integer"
- LeetCode---(13)Roman to Integer
- leetcode-13Roman to Integer
- leetcode 13: Roman to Integer
- Leetcode 13 Roman to Integer
- vb作业
- 对于 前K短路径问题 和 A*算法 的一些小小总结
- apache shiro集群实现(二)— cache共享
- 用户反馈怎么用?千万别按照用户的要求直接设计产品!
- ISR和DPC
- LeetCode 13 Roman to Integer
- 我在华勤的那些日子-----------Android的laucher3源码剖析(一)
- Caused by: android.database.sqlite.SQLiteException: no such column:
- VC++2010工程中加入SplashScreen的启动画面
- hudson自动化配置小结
- IOS :切回app时、会有闪现、闪现一次主屏幕的现象
- 使用U盘制作OS X 不同版本的安装盘
- mount命令详解
- 关于BitmapFactory.decodeStream(is)方法无法正常解码为Bitmap对象的解决方法