From 42f55f69259b2b28cfe56891b38373705ca26d44 Mon Sep 17 00:00:00 2001 From: Wander_lust Date: Thu, 29 Jan 2026 01:14:19 +0530 Subject: [PATCH] Implement integer to Roman numeral conversion --- leetcode/lc12/IntToRom.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/leetcode/lc12/IntToRom.cpp b/leetcode/lc12/IntToRom.cpp index e69de29..cf84095 100644 --- a/leetcode/lc12/IntToRom.cpp +++ b/leetcode/lc12/IntToRom.cpp @@ -0,0 +1,20 @@ +class Solution { +public: + string intToRoman(int num) { + const vector> valueSymbols = { + {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; + for(auto const &[value,symbol]: valueSymbols){ + if(num == 0) + break; + while(num>=value){ + res+=symbol; + num-=value; + + } + } + return res; + } +};