Golang | Leetcode Golang题解之第12题整数转罗马数字

题解:

题解:

Go 复制代码
var (
    thousands = []string{"", "M", "MM", "MMM"}
    hundreds  = []string{"", "C", "CC", "CCC", "CD", "D", "DC", "DCC", "DCCC", "CM"}
    tens      = []string{"", "X", "XX", "XXX", "XL", "L", "LX", "LXX", "LXXX", "XC"}
    ones      = []string{"", "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX"}
)

func intToRoman(num int) string {
    return thousands[num/1000] + hundreds[num%1000/100] + tens[num%100/10] + ones[num%10]
}
相关推荐
TracyCoder12324 分钟前
LeetCode Hot100(8/100)—— 438. 找到字符串中所有字母异位词
算法·leetcode
June bug1 小时前
(#数组/链表操作)最长上升子序列的长度
数据结构·程序人生·leetcode·链表·面试·职场和发展·跳槽
hadage2331 小时前
--- 力扣oj柱状图中最大的矩形 单调栈 ---
算法·leetcode·职场和发展
json{shen:"jing"}1 小时前
18. 四数之和
数据结构·算法·leetcode
多米Domi0112 小时前
0x3f 第42天 复习 10:39-11:33
算法·leetcode
议题一玩到2 小时前
#leetcode# 1984. Minimum Difference Between Highest and Lowest of K Scores
数据结构·算法·leetcode
漫随流水2 小时前
leetcode回溯算法(90.子集Ⅱ)
数据结构·算法·leetcode·回溯算法
June bug2 小时前
(#数组/链表操作)合并两个有重复元素的无序数组,返回无重复的有序结果
数据结构·python·算法·leetcode·面试·跳槽
普贤莲花3 小时前
取舍~2026年第4周小结---写于20260125
程序人生·算法·leetcode
x70x803 小时前
Go中nil的使用
开发语言·后端·golang