My C++ solution, simple, only 1 line with 25 ms running time.


  • 1
    Q
    string intToRoman(int num) {
            string Roman[4][10] = {
                {"", "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX"},
                {"", "X", "XX", "XXX", "XL", "L", "LX", "LXX", "LXXX", "XC"},
                {"", "C", "CC", "CCC", "CD", "D", "DC", "DCC", "DCCC", "CM"},
                {"", "M", "MM", "MMM"}
            };
            return Roman[3][num/1000%10]+Roman[2][num/100%10]+Roman[1][num/10%10]+Roman[0][num%10];
    }

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.