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) {
int n = s.size();
if(n == 0) return 0;
map<char, int> m;
m['I'] = 1;
m['V'] = 5;
m['X'] = 10;
m['L'] = 50;
m['C'] = 100;
m['D'] = 500;
m['M'] = 1000;
int res = m[s[n-1]];
for(int i = n-2; i >= 0; --i)
res += m[s[i]] < m[s[i+1]] ? -m[s[i]] : m[s[i]];
return res;
}
};