Leetcode Integer to Roman

时间:2023-03-09 05:13:50
Leetcode Integer to Roman

Given an integer, convert it to a roman numeral.

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

int key[]={, , , , ,, , , , , , , };
string romans[]={"M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I"}; class Solution {
public:
string intToRoman(int num) {
for(int i = ; i < ; ++ i){
if(key[i]<= num) return romans[i]+intToRoman(num-key[i]);
}
return "";
}
};