博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Roman to Integer
阅读量:4075 次
发布时间:2019-05-25

本文共 639 字,大约阅读时间需要 2 分钟。

Roman to Integer

Given a roman numeral, convert it to an integer.

Input is guaranteed to be within the range from 1 to 3999.

Java代码:

public class Solution {public int romanToInt(String s) {		Map
map = new HashMap
(); 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 i, total, pre, cur; total = map.get(s.charAt(0)); for (i = 1; i < s.length(); i++) { pre = map.get(s.charAt(i - 1)); cur = map.get(s.charAt(i)); if (cur <= pre) { total += cur; } else { total = total - pre * 2 + cur; } } return total; }}
 

转载地址:http://dnuni.baihongyu.com/

你可能感兴趣的文章
【Unity3d】Ray射线初探-射线的原理及用法
查看>>
迄今最深入、最专业的Hololens评测结果,美国AR大咖艾迪·奥夫曼现身说法
查看>>
全息眼镜HoloLens可快速捕捉真人3D图像
查看>>
copy-paste component
查看>>
【Unity】矩阵运算
查看>>
理解向量运算
查看>>
正弦 sin 余弦 cos
查看>>
微积分
查看>>
Vector3 *2 ,ToString()自动四舍五入
查看>>
2016年秋季的我,work with hololens
查看>>
叉积与点积
查看>>
λ怎么 读
查看>>
Rect 和 Bounds
查看>>
HOLOLENS不适合加天空盒
查看>>
Unity UI on hololens
查看>>
Unity 下载存档
查看>>
3D游戏常用技巧Normal Mapping (法线贴图)原理解析——基础篇
查看>>
学UNITY的基础
查看>>
What is a RaycastHit normal?
查看>>
Vector3.forward
查看>>