Login light

https://leetcode-cn.com/problems/integer-to-roman/

贪心算法,从最高位遍历到最低位,num大于当前值则匹配罗马字符,直到num==0

#贪心
class Solution:
    def intToRoman(self, num: int) -> str:
        s = ['M','CM','D','CD','C','XC','L','XL','X','IX','V','IV','I']
        v = [1000,900,500,400,100,90,50,40,10,9,5,4,1]
        ret = ''
        while num > 0:
            for i in v:
                if num / i >= 1:
                    ret += (s[v.index(i)] * int((num - num % i) / i))
                    num = num % i
                    break
        return ret