12. Integer to Roman

作者: d1497e8e780a | 来源:发表于2019-01-31 17:37 被阅读1次

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
    }
}

相关文章

网友评论

    本文标题:12. Integer to Roman

    本文链接:https://www.haomeiwen.com/subject/pjklsqtx.html