-
Notifications
You must be signed in to change notification settings - Fork 2
/
Binary-Watch.py
26 lines (25 loc) · 889 Bytes
/
Binary-Watch.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
class Solution(object):
def readBinaryWatch(self, num):
e = []
for i in [8, 4, 2, 1]:
e.append({'row': 'top', 'num': i})
for i in [32, 16, 8, 4, 2, 1]:
e.append({'row': 'lower', 'num': i})
times = []
for val in itertools.combinations(e, num):
hours = 0
mins = 0
r = {'top': [], 'bottom': []}
for v in val:
if (v['row'] == 'top'):
hours += v['num']
r['top'].append(v['num'])
else:
mins += v['num']
r['bottom'].append(v['num'])
if ((mins < 60) and (hours < 12)):
x = '{}:{}'.format(str(hours).zfill(1), str(mins).zfill(2))
r['x'] = x
print r
times.append(x)
return sorted(times)