class Solution
{
public:
std::string sym_table[13] = {"M","CM","D","CD","C","XC","L","XL","X","IX","V","IV","I"};
int val_table[13] = {1000,900,500,400,100,90,50,40,10,9,5,4,1};
string intToRoman(int num)
{
std::string result;
for(int i =0; i< 13 && num >=0; i++)
{
while(val_table[i] <= num)
{
num -= val_table[i];
result =result + sym_table[i];
}
}
return result;
}
};
12. Integer to Roman | Leetcode
最新推荐文章于 2024-09-08 17:41:31 发布