- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path401_binary_watch.py
More file actions
Latest commit
89 lines (80 loc) · 3.02 KB
/
Copy path401_binary_watch.py
File metadata and controls
89 lines (80 loc) · 3.02 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
classSolution:
defreadBinaryWatch(self, num: int) ->List[str]:
defcombine_hour_and_minute(hour: List[str], minute: List[str]) ->List[str]:
ans= []
foriinrange(len(hour)):
forjinrange(len(minute)):
ans.append(hour[i] +':'+minute[j])
returnans
defcal_hour_value(n):
arr= [1, 2, 4, 8]
tmp=combination(arr, n)
ans= []
fornumsintmp:
t=sum(nums)
ift<12:
ans.append(str(t))
else:
pass
returnans
defcal_minute_value(n):
arr= [1, 2, 4, 8, 16, 32]
tmp=combination(arr, n)
ans= []
fornumsintmp:
t=sum(nums)
ift==0:
ans.append('00')
elif1<=t<=9:
ans.append('0'+str(t))
elif10<=t<60:
ans.append(str(t))
else:
pass
returnans
defcombination(L, k): # C(n,k) = C(n-1,k) + C(n-1,k-1)
ifk>=len(L):
return [L]
ifk==0:
return [[]]
T1=combination(L[0:len(L)-1], k-1)
T2=combination(L[0:len(L)-1], k)
T= []
foreinT1:
e.append(L[len(L)-1])
T.append(e)
returnT2+T
ifnum==0:
return ['0:00']
elifnum>10:
return []
else:
ifnum<=4:
ans= []
foriinrange(num+1):
hour=cal_hour_value(i)
minute=cal_minute_value(num-i)
ans.extend(combine_hour_and_minute(hour, minute))
returnans
else:
ans= []
foriinrange(5):
hour=cal_hour_value(i)
minute=cal_minute_value(num-i)
ans.extend(combine_hour_and_minute(hour, minute))
returnans
'''
This is my personal record of solving Leetcode Problems.
If you have any questions, please discuss them in [Issues](https://github.com/mengxinayan/leetcode/issues).
Copyright (C) 2020-2022 mengxinayan
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
'''