LeetCode 12. 整数转罗马数字 思路进制打表,对应大小组成罗马数字。 代码123456789101112131415161718class Solution {public: string intToRoman(int num) { int n=num; vector<int> bits={1000,900,500,400,100,90,50,40,10,9,5,4,1}; vector<string> Louma={"M","CM","D","CD","C","XC","L","XL","X","IX","V","IV","I"}; string res=""; while(n>0){ int i=0; while(n<bits[i]){ i++; } res+=Louma[i]; n-=bits[i]; } return res; }}; [^1]: note leetcode code leetcode 本博客所有文章除特别声明外,均采用 CC BY-SA 4.0 协议 ,转载请注明出处! LeetCode 433. 最小基因变化 上一篇 LeetCode 13. 罗马数字转整数 下一篇