Roman to Integer

PHOTO EMBED

Tue Nov 08 2022 16:17:11 GMT+0000 (Coordinated Universal Time)

Saved by @Ranjan_kumar #c++

class Solution {
public:
    int romanToInt(string s) {
        
        map<char,int>mp;
        mp['I']=1;
        mp['V']=5;
        mp['X']=10;
        mp['L']=50;
        mp['C']=100;
        mp['D']=500;
        mp['M']=1000;
       
        int n=s.size(),num,sum=0;
        for(int i=0;i<n;i++)
        {
            if(mp[s[i]]<mp[s[i+1]])
            {
                sum-=mp[s[i]];
            }
            else 
            {
                sum+=mp[s[i]];
            }
        }
        
        return sum;
    }
};
content_copyCOPY

https://leetcode.com/problems/roman-to-integer/