Roman to Integer -- LeetCode

原题链接: http://oj.leetcode.com/problems/roman-to-integer/
这道题和 Integer to Roman 一样,也是整数和罗马数字的转换。思路也比较简单,就是维护一个整数,然后如果1下一个字符是对应位的5或者10则减对应位的1,否则加之。遇到5或者10就直接加上对应位的5或者10。时间复杂度是O(字符串的长度),空间复杂度是O(1)。代码如下:
public int romanToInt(String s) {

    if(s==null || s.length()==0)
        return 0;
    int res = 0;
    for(int i=0;i
题目思路比较清晰,就是简单的字符串操作。

你可能感兴趣的:(Roman to Integer -- LeetCode)