LeetCode 0012 - Integer to Roman

2021-08-11 10:18:23 浏览数 (1)

Integer to Roman

Desicription

Given an integer, convert it to a roman numeral.

Input is guaranteed to be within the range from 1 to 3999.

Solution

代码语言:javascript复制
class Solution {
public:
    string intToRoman(int num) {
        string thousand[4] = {"", "M", "MM", "MMM"};
        string hundred[10] = {"", "C", "CC", "CCC", "CD", "D", "DC", "DCC", "DCCC", "CM"};
        string ten[10] = {"", "X", "XX", "XXX", "XL", "L", "LX", "LXX", "LXXX", "XC"};
        string one[10] = {"", "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX"};
        return thousand[num/1000]   hundred[(num00)/100]   ten[(num0)/10]   one[num];
    }
};

0 人点赞