Solution in C++


  • 0
    T

    '''class Solution {
    public:
    const std::unordered_map<char, int> unique_roman {
    {'I', 1},
    {'V', 5},
    {'X', 10},
    {'L', 50},
    {'C', 100},
    {'D', 500},
    {'M', 1000}};

    int romanToInt(string s) {
        int result = 0;
        int last_value = 0;
        for(int i = s.length() - 1; i >= 0; i--) {
            int value = unique_roman.find(s.at(i))->second;
            cout<<value;
            if(value < last_value)
                result = result - value;
            else 
                result = result + value;
            last_value = value;
        }
        return result;
    }
    

    };
    '''


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.