LeetCode: Regular Expression Matching 解题报告

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

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

SOLUTION 1:

思路:

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

View Code

 

GITHUB 代码:

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

 

posted on 2014-11-23 18:43  Yu's Garden  阅读(421)  评论(0编辑  收藏  举报

导航