OneCompiler

Roman to Integer

1632

Example heading with h2 size

Example heading with h3 size

class Solution {
public int romanToInt(String s) {
map<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);

    int result = map.get(s.chaAt(s.length()-1));
    for(int i = s.length()-2; i >= 0 ; i--){
        if(map.get(s.charAt(i)) < map.get(s.charAt(i+1))){
            result-=map.get(s.charAt(i));

        }  else{
            result+=map.get(s.charAt(i));
        }  
     }


}

}************

****