1 line python code


  • -12
    O
    class Solution(object):
        def intToRoman(self, num):
            """
            :type num: int
            :rtype: str
            """
            return (num//1000) * 'M' + (num%1000 >= 900) * 'CM' + (500 <= num%1000 < 900) * 'D' + \
                    (400 <= num%1000 < 500) * 'CD' + (num%500 < 400) * ((num%500)//100) * 'C' + \
                    (num%100 >= 90) * 'XC' + (50 <= num%100 < 90) * 'L' + \
                    (40 <= num%100 < 50) * 'XL' + (num%50 < 40) * ((num%50)//10) * 'X' + \
                    (num%10 >= 9) * 'IX' + (5 <= num%10 < 9) * 'V' + \
                    (num%10 == 4) * 'IV' + (num%5 < 4) * (num%5) * 'I'

  • 5
    D

    In principle, any program could be 1 line...


  • 0
    W

    1 line..............


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.