419
来源:互联网 发布:unix和linux和windows 编辑:程序博客网 时间:2024/05/31 18:38
2017.10.27
public class Solution { /* * @param s: Roman representation * @return: an integer */public int romanToInt(String s){HashMap<Character,Integer> map = new HashMap<>();map.put('I', 1);map.put('X', 10);map.put('C', 100);map.put('M', 1000);map.put('V', 5);map.put('L', 50);map.put('D', 500);if(s.length() == 0){return 0;}if(s.length() == 1){return map.get(s.charAt(0));}int res = 0;for(int i = s.length()-1; i >= 0; i--){char c = s.charAt(i);if(c == 'I' || c == 'X' || c == 'C'){ if(i == s.length() - 1){res = res + map.get(c);} else if(map.get(c) < map.get(s.charAt(i+1))){res = res - map.get(c);}else {res = res + map.get(c);}}else{res = res + map.get(c);}}return res;}}
阅读全文
0 0
- 419
- 419
- 419
- 419
- ocp-419
- 419 含义
- Leetcode 419
- #419 Roman to Integer
- CF #419 div2
- Codeforces Round #419
- codeforces#419 B q
- LeetCode.419 Arithmetic Slices
- lintcode-罗马数字转整数-419
- ZZL的cf#419 div2
- Codeforces Round #419 (Div. 2)
- Codeforces Round#419 (div.1)
- Codeforces Round #419 (Div. 2)
- Codeforces Round #419 (Div. 2)
- Cday12
- ThinkPHP--initialize()方法
- 删除链表的中间节点和a/b处的节点
- MYSQL-远程连接报:Host 'xxxxx' is not allowed to connect to this MySQL server
- IMP-00017: 由于 ORACLE 错误 6550解决办法
- 419
- hive 行转列 分割
- 如何修改jupyter notebook的 默认目录
- 使用 hibernate 存取大对象数据类型(clob和blob)
- JavaScript原型prototype属性
- Hadoop安装后dataNode无法启动
- TEXMACS在ubuntu下的使用
- Blade:一款简洁优雅、微内核设计的Java Web框架
- 打造自己的Ubuntu渗透利器--msf、nessus安装