class Solution {
public:
string intToRoman(int num) {
string Roman[13] = {"M","CM","D","CD","C","XC","L","XL","X","IX","V","IV","I"};
int data[13] = {1000,900,500,400,100,90,50,40,10,9,5,4,1};
string out;
int start = 0;
while(num>0){
if(num-data[start]>=0){
out+=Roman[start];
num-=data[start];
}else
start++;
}
return out;
}
};
Leetcode学习笔记(12. 整数转罗马数字)
最新推荐文章于 2023-12-15 11:36:29 发布