-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path401. 二进制手表.py
More file actions
38 lines (29 loc) · 964 Bytes
/
401. 二进制手表.py
File metadata and controls
38 lines (29 loc) · 964 Bytes
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
27
28
29
30
31
32
33
34
35
36
37
38
from typing import List
import datetime
from itertools import combinations
class Solution:
def readBinaryWatch(self, turnedOn: int) -> List[str]:
times = []
for i in [1, 2, 4, 8]:
times.append(datetime.timedelta(hours=i))
for i in [1, 2, 4, 8, 16, 32]:
times.append(datetime.timedelta(minutes=i))
if turnedOn > len(times):
return []
result = []
for t in combinations(times, turnedOn):
minute = datetime.timedelta()
hour = datetime.timedelta()
for t_ in t:
if t_.seconds % 3600 == 0:
hour += t_
else:
minute += t_
if minute.seconds >= 3600:
continue
if hour.seconds > 11 * 3600:
continue
result.append(str(hour + minute)[:-3])
return result
s = Solution()
print(s.readBinaryWatch(9))