码迷,mamicode.com
首页 > 其他好文 > 详细

LeetCode: Roman to Integer 解题报告

时间:2014-11-23 21:33:17      阅读:223      评论:0      收藏:0      [点我收藏+]

标签:des   cWeb   style   blog   http   io   ar   os   sp   

Roman to Integer
Given a roman numeral, convert it to an integer.

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

bubuko.com,布布扣

SOLUTION 1: 

思路:

从后往前遍历罗马数字,如果某个数比前一个数小,则把该数在结果中减掉;
反之,则在结果中加上当前这个数;

bubuko.com,布布扣View Code

 

GITHUB 代码:

https://github.com/yuzhangcmu/LeetCode_algorithm/blob/master/string/RomanToInt.java

 

LeetCode: Roman to Integer 解题报告

标签:des   cWeb   style   blog   http   io   ar   os   sp   

原文地址:http://www.cnblogs.com/yuzhangcmu/p/4117312.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!