LeetCode 13 | ROMAN TO INTEGER | C++ [ Approach and Code Explanation]

preview_player
Показать описание
This video contains detailed explanation on #LeetCode problem 13 #RomanNumber To Integer along with code in C++.

The following question has been asked in various interviews including #Amazon , #Facebook , #Google , #Uber , #Microsoft , #LinkedIn etc.

Рекомендации по теме
Комментарии
Автор

this is so simple and easy, and yet I couldn't come up with it...

moritzwagner
Автор

The same approach but more easy in coding:
```
int romanToInt(string s) {
map<char, int> roman{
{'I', 1}, {'V', 5}, {'X', 10}, {'L', 50}, {'C', 100}, {'D', 500}, {'M', 1000}
};
int num{0};
for(size_t i{0}; i< s.length(); ++i){
if(roman[s[i]] < roman [s[i+1]]){
num += (roman[s[i+1]] - roman[s[i]]);
++i;
}
else
num += roman[s[i]];
}
return num;
}

```

mohamedmuslim
Автор

can i use the type enum to set the values to the letters ?

unLinuxeroMas
Автор

Excuse me, in line 22, why you write : i = i + 2 ?

hoangvacban
Автор

Why did you not included increment inside for() statement is it acceptable like that?

JayShri-totp
Автор

Bhai tu Java use kar raha hain aur likha tune C++ hain

jatinmahor