算法设计与应用基础
来源:互联网 发布:手机网游制作软件 编辑:程序博客网 时间:2024/04/28 21:06
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.
Subscribe to see which companies asked this question.
public static int romanToInt(String s) {int res = 0;for (int i = s.length() - 1; i >= 0; i--) {char c = s.charAt(i);switch (c) {case 'I':res += (res >= 5 ? -1 : 1);break;case 'V':res += 5;break;case 'X':res += 10 * (res >= 50 ? -1 : 1);break;case 'L':res += 50;break;case 'C':res += 100 * (res >= 500 ? -1 : 1);break;case 'D':res += 500;break;case 'M':res += 1000;break;}}return res;}
0 0
- 算法设计与应用基础
- 算法设计与应用基础
- 算法设计与应用基础
- 算法设计与应用基础
- 算法设计与应用基础
- 算法设计与应用基础
- 算法设计与应用基础
- 算法设计与应用基础
- 算法设计与应用基础
- 算法设计与应用基础
- 算法设计与应用基础
- 算法设计与应用基础
- 算法设计与应用基础
- 算法设计与应用基础
- 算法设计与应用基础
- 算法设计与应用基础
- 算法设计与应用基础
- 算法设计与应用基础
- scala学习指南
- linux inotify功能和用法
- 常见数据结构与算法整理总结
- 练习系统 实验三 大整数乘法
- Cocos2dx开发环境配置
- 算法设计与应用基础
- 关于Spark学习的问题总结
- 媒体传输端口(pjmedia_transport)
- Help
- 学习笔记——数据挖掘过程与方法 Data Mining
- IIS8.5关于“ 配置错误 不能在此路径中使用此配置节”的解决办法
- 2011年中山笔试
- OGG 11g Checkpoint 详解
- 如何用电脑cmd获取手机cpu信息