[LeetCode][easy]Roman to Integer
从低位到高位,如果上一位代表的数值比该位小,则减,否则加。
class Solution {private static HashMap<Character, Integer> map = new HashMap<>();static {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);}public int romanToInt(String s) {int result = 0;if (s == null || s.length() == 0) {return result;}char[] c = s.toCharArray();int i = c.length - 1;for (; i>0; ) {char low = c[i];char high = c[i-1];int lowNum = map.get(low);int highNum = map.get(high);if (highNum < lowNum) {result += lowNum - highNum;i -= 2;continue;}result += lowNum;i--;}if (i == 0) {result += map.get(c[0]);}return result;}
}
[LeetCode][easy]Roman to Integer相关推荐
- LeetCode 13. Roman to Integer
问题链接 LeetCode 13. Roman to Integer 题目解析 将罗马数字转换成普通数字. 解题思路 先简单了解一下什么是罗马数字. 基本字符:I,V,X,L,C,D,M 相应的阿拉伯 ...
- leetcode 8 Roman to Integer C++实现
leetcode 8 Roman to Integer C++实现 罗马数字包含以下七种字符: I, V, X, L,C,D 和 M. 字符 数值 I 1 V 5 X 10 L 50 C 100 D ...
- [LeetCode][JavaScript]Roman to Integer
Roman to Integer Given a roman numeral, convert it to an integer. Input is guaranteed to be within t ...
- 【leetcode】Roman to Integer
题目描述: Given a roman numeral, convert it to an integer. Input is guaranteed to be within the range fr ...
- LeetCode: 13. Roman to Integer
051106 题目 Roman numerals are represented by seven different symbols: I, V, X, L, C, D and M. Symbol ...
- # LeetCode集锦(四) - 第13题 Roman To Integer
LeetCode集锦(四) - 第13题 Roman To Integer 问题 Roman numerals are represented by seven different symbols: ...
- Roman to Integer - LeetCode
目录 题目链接 注意点 解法 小结 题目链接 Roman to Integer - LeetCode 注意点 大的数字在小的数字左边是正常情况,要考虑的是小的数字在大的数字右边的那8种情况 解法 解法 ...
- LeetCode刷题实战(13):Roman to Integer
题目描述: 13 Roman to Integer 49.5% Easy Roman numerals are represented by seven different symbols: I, ...
- LeetCode算法入门- Roman to Integer Integer to Roman -day8
LeetCode算法入门- Roman to Integer -day8 Roman to Integer: 题目描述: Roman numerals are represented by seven ...
- leetcode 12 ,13 Integer to Roman amp;amp;Roman to Integer 罗马与阿拉伯数组转换
12 Integer to Roman 13 Roman to Integer 有可能不注意的结果: class Solution {public:/*1.相同的数字连写,所表示的数等于这些数字相加得 ...
最新文章
- 小小的Python编程故事
- mongo explain分析详解
- css中vertical-align生效
- 记录php项目遇到502和504 Bad Gateway问题
- workflow-工作流
- 老王教您怎么做cass7.1 8.0 9.1所有系列的复制狗 加密狗 破解狗
- 【第一组】第十五次冲刺例会纪要
- ae怎么设置gpu渲染_AE/PR mac版如何开启GPU加速渲染?
- 【读官方文档,学原味技术】SpringBoot-Staters和自定义Starter
- python函数带()与否
- 形象标识 新松机器人_辽宁日报- 厉害了新松!获评年度“新锐品牌”成为国家形象名片...
- Python打印九九乘法表---左上三角、左下三角、右上三角、右下三角形格式
- 【转】PC机安装MAC虚拟机
- Python 手写数字识别-1
- javaMail实现发邮件功能
- (JS)Javascript之Ajax
- Agilent安捷伦81150A脉冲信号发生器 信号源
- 运用spss modeler运用支持向量机_四个小项目完全解读支持向量机
- 沉降观测曲线图 沉降观测汇总_GD-C4-6320建筑物沉降观测记录(含说明、汇总表、布置图、曲线图)...
- 东北大学金工实习考试及答案
热门文章
- 视频直播技术(三):低延时直播经验总结
- 20145240《Java程序设计》第二周学习总结
- [转]Birdfont 2.10 发布,字体编辑器
- 南阳oj-----n-1位数(多解法汇总)
- python输入输出格式_Python基础-用户的输入及格式化输出 | 【韩涛博客】
- python3安装pymysql_ubuntu16.04 python3安装pymysql错误
- java redis 队列 抢购_redis使用watch秒杀抢购实现思路
- 压力测试工具JMeter入门教程
- 山大824计算机基础,山大考研辅导班:山东大学2020年824计算机基础考研自命题科目考试大纲...
- 【2019杭电多校第七场1001=HDU6646】A+B=C(思维+多细节)