Archi solution( u will luv it 😊)


#1

// A short and easy solution in known as Archi solution:blush:
int Solution::romanToInt(string A) {
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;
vectorv;
int cm=INT_MIN;
int ans=0;
for(int i=A.size()-1;i>=0;i–)
{
if(mp[A[i]]<cm)
{
v.push_back(-mp[A[i]]);
}
else
{
v.push_back(mp[A[i]]);
cm=mp[A[i]];
}

}
for(auto it:v)
ans+=it;
return ans;

}