Python - extremely simple solution


  • 0
    A
    class Solution(object):
        def readBinaryWatch(self, num):
            """
            :type num: int
            :rtype: List[str]
            """
            import itertools as it
            hrs = {0: ['0:'], 1:['1:','2:','4:','8:'], 2:['3:','5:','9:','6:','10:'], 3:['7:','11:']}
            mins = {0:['00'],\
                    1:['01', '02', '04', '08', '16', '32'], \
                    2:['03', '05', '09', '17', '33', '06', '10', '18', '34', '12', '20', '36', '24', '40', '48'], \
                    3:['07', '11', '19', '35', '13', '21', '37', '25', '41', '49', '14', '22', '38', '26', '42', '50', '28', '44', '52', '56'], \
                    4:['15', '23', '39', '29', '45', '53', '54', '30', '46', '27', '43', '51',  '57', '58'],\
                    5:['31', '47', '55', '59']}
            # num = min(8, num)
            res = []
            for m in range(4):
                if num - m > 5 or num - m < 0:
                    continue
                else:
                    res += [pair[0]+pair[1] for pair in it.product(hrs[m], mins[num-m])]
            return res
    

Log in to reply
 

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