LeetCode 12 Integer To Roman | Strings | C++ [ Algorithm + Code explanation]

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

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

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

Below is the Simple code for above approch

#include <iostream>
using namespace std;
string integer_to_Roman(int n) {
string str_romans[] = {"M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I"};
int values[] = {1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1}; string result = "";
for (auto int i = 0; i < 13; ++i) {
while(n - values[i] >= 0) {
result += str_romans[i];
n -= values[i];
}
}
return result;
}

eziosan
Автор

Sir, What is complexity of this solution?

alwayshappy
Автор

for 500, 50, 5 we dont need while, if will work.

swasthikadev
Автор

What kind of solution is this? Should have used maps.

abhinavkumar
Автор

Why is it a "while if while if" why don't you just make it all ifs or or all whiles?

MonteLogic
welcome to shbcf.ru