Java Solution


  • 0
    V

    public int romanToInt(String s) {
    HashMap<Character, Integer> 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);

    	String after = s.replaceAll("IV", "IIII").replaceAll("IX", "VIIII").replaceAll("XL", "XXXX").replaceAll("XC", "XXXXXXXXX")
    			.replaceAll("CD", "CCCC").replaceAll("CM", "CCCCCCCCC");
    
    	
    
    	return sum;
    }

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.