Given a roman numeral, convert it to an integer.
Input is guaranteed to be within the range from 1 to 3999.
class Solution {
public:
int romanToInt(string s) {
unordered_map<char, int> m{{'I', 1}, {'V', 5}, {'X', 10}, {'L', 50}, {'C', 100}, {'D', 500}, {'M', 1000}};
int res = 0;
for(int i = 0 ; i< s.size();++i){
int val = m[s[i]];
if(i==s.size()-1||m[s[i]]>=m[s[i+1]])
res+=val;
else
res-=val;
}
return res;
}
};