i am so sure that now anytime i see this or any similar question, this approach will save my time sm... thank you
@thaman7019 ай бұрын
Nicely explained brother ❤
@ShivamGupta-cx3hy2 жыл бұрын
understood clearly
@codestorywithMIK2 жыл бұрын
Glad i could help. Appreciate your kind words ❤️
@iamnottech89183 ай бұрын
u are a life saver....
@069_bhanuprasadgoud3 Жыл бұрын
good explaination
@codestorywithMIK Жыл бұрын
Thank you ❤️😇
@wearevacationuncoverers9 ай бұрын
crystal clear. Thanks a lot
@itsme98776 ай бұрын
❤
@Saurabh_919 ай бұрын
k videos
@rishabhverma6318 Жыл бұрын
string intToRoman(int num) { string romanSymbols[] = {"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 ans=""; // jb convert krte h to sbse bda number choose krte hai for(int i=0;i=values[i]){ ans+=romanSymbols[i]; num-=values[i]; } } return ans; }
@anmolbansal40094 ай бұрын
why we used static before the vector?? what does it do? code is running fine without it also....why we use it then?
@syedsuffiyan4747Ай бұрын
it wont get initialized continuosly since all values are constant in the array so we use static keyword
@vinniverma4693 күн бұрын
i have a better approch i used a custom hash (becuase hashmap does not gaurentee order which is necessary for this ques ) string intToRoman(int num) { vector roman = { {1000, "M"}, {900, "CM"}, {500, "D"}, {400, "CD"}, {100, "C"}, {90, "XC"}, {50, "L"}, {40, "XL"}, {10, "X"}, {9, "IX"}, {5, "V"}, {4, "IV"}, {1, "I"} }; string res=""; while(num>0){ for( auto & x:roman){ int times=num/x.first; while(times>0){ res+=x.second; times--; } num=num%x.first; } } return res; }
@aashukumar63653 ай бұрын
tc and sc?
@kallabhalu60069 ай бұрын
One confusion, why didnt we use hashmap to store values as it is more intutive to store mapping of numbers to character. Please Answer
@jewelchakraborty97178 ай бұрын
My suggestion is to use TreeMap in descending order instead of normal hashmap
@mma-dost9 ай бұрын
int romanToInt(string s) { unordered_map 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.length(); int prev = 0; int number = 0; for(int i = n-1; i > -1; i--){ if(prev > mp[s[i]]) number = number - mp[s[i]]; else number = number + mp[s[i]]; prev = mp[s[i]]; } return number; } Is this solution, okay? Wrote this myself looks good to me. If you can correct something guys, please reply.