• # 39ms, 99%

``````    _h = {0: [0], 1: [1, 2, 4, 8], 2: [3, 5, 9, 6, 10], 3: [7, 11]}
_m = {0: [0], 1: [1, 2, 4, 8, 16, 32], 2: [3, 5, 9, 17, 33, 6, 10, 18, 34, 12, 20, 36, 24, 40, 48], 3: [7, 11, 19, 35, 13, 21, 37, 25, 41, 49, 14, 22, 38, 26, 42, 50, 28, 44, 52, 56], 4: [15, 23, 39, 27, 43, 51, 29, 45, 53, 57, 30, 46, 54, 58], 5: [31, 47, 55, 59]}

"""
:type num: int
:rtype: List[str]
"""
if 5 not in Solution._m:
import itertools
Solution._h[2] = [sum(x) for x in itertools.combinations(Solution._h[1], 2) if sum(x) < 12]
Solution._h[3] = [sum(x) for x in itertools.combinations(Solution._h[1], 3) if sum(x) < 12]
Solution._m[2] = [sum(x) for x in itertools.combinations(Solution._m[1], 2) if sum(x) < 60]
Solution._m[3] = [sum(x) for x in itertools.combinations(Solution._m[1], 3) if sum(x) < 60]
Solution._m[4] = [sum(x) for x in itertools.combinations(Solution._m[1], 4) if sum(x) < 60]
Solution._m[5] = [sum(x) for x in itertools.combinations(Solution._m[1], 5) if sum(x) < 60]
print(Solution._h)
print(Solution._m)

ans = []
for i in xrange(num+1):
if (i in Solution._h) and (num-i in Solution._m):
ans += ['{:d}:{:02d}'.format(x,y) for x in Solution._h[i] for y in Solution._m[num-i]]
return ans

``````

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