标签:size char return ring ++ roman order for integer
class Solution { public: int romanToInt(string s) { int res = 0; unordered_map<char, int> m{{‘I‘, 1}, {‘V‘, 5}, {‘X‘, 10}, {‘L‘, 50}, {‘C‘, 100}, {‘D‘, 500}, {‘M‘, 1000}}; for (int i = 0; i < s.size(); ++i) { if (i == 0 || m[s[i]] <= m[s[i - 1]]) res += m[s[i]]; else res += m[s[i]] - 2 * m[s[i - 1]]; } return res; } };
标签:size char return ring ++ roman order for integer
原文地址:http://www.cnblogs.com/wangkun1993/p/6366635.html