class Solution {
public:
int romanToInt(string s) {
unordered_map <char, int>m;
vector<int> v;
int size = s.length(), sum = 0;
m['I'] = 1;
m['V'] = 5;
m['X'] = 10;
m['L'] = 50;
m['C'] = 100;
m['D'] = 500;
m['M'] = 1000;
for (int i = 0; i < size; i++) {
v.push_back(m[s[i]]);
}
int i = 0, lastOne = 0;
while (i < size) {
if (i != size - 1) {
if (v[i] < v[i + 1]) {
sum += (v[i + 1] - v[i]);
i++;
} else {
sum += v[i];
}
} else {
sum += (v[size - 1]);
}
i++;
}
return sum;
}
};