Swift 4.2 没什么好解法 这样写比较容易看懂
class Solution {
func intToRoman(_ num: Int) -> String {
var M = ["","M","MM","MMM"]
var C = ["","C","CC","CCC","CD","D","DC","DCC","DCCC","CM"]
var X = ["","X","XX","XXX","XL","L","LX","LXX","LXXX","XC"]
var I = ["","I","II","III","IV","V","VI","VII","VIII","IX"]
let s:String = M[num/1000] + C[(num%1000)/100] + X[(num%100)/10] + I[num%10]
return s
}
}
网友评论