13. Roman to Integer

罗马数字转整数,如图


13. Roman to Integer_第1张图片
image.png

需要注意的是IX,IV这样的
java环境

class Solution {
    public int romToInt(char s){
        switch(s){
            case 'I':
                return 1;
            case 'X':
                return 10;
            case 'V':
                return 5;
            case 'L':
                return 50;
            case 'C':
                return 100;
            case 'D':
                return 500;
            case 'M':
                return 1000;
            default:
                return 0;
        }
    }
    public int romanToInt(String s) {
        int res = 0;
        for(int i=0;i

你可能感兴趣的:(13. Roman to Integer)