leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

0012.cpp (545B)


      1 class Solution {
      2   public:
      3     vector<vector<string>> vvs = {
      4         {"", "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX"},
      5         {"", "X", "XX", "XXX", "XL", "L", "LX", "LXX", "LXXX", "XC"},
      6         {"", "C", "CC", "CCC", "CD", "D", "DC", "DCC", "DCCC", "CM"},
      7         {"", "M", "MM", "MMM", "*", "*", "*", "*", "*", "*"},
      8     };
      9 
     10     string intToRoman(int num) {
     11         int exp = 0;
     12         string res = "";
     13         do {
     14             res = vvs[exp++][num % 10] + res;
     15         } while ((num /= 10) > 0);
     16 
     17         return res;
     18     }
     19 };