-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathleetcode401.py
37 lines (33 loc) · 945 Bytes
/
leetcode401.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
27
28
29
30
31
32
33
34
35
36
37
class Solution(object):
def num_of_ones(self,x):
d=[0]
if x==0:
return 0
else:
for i in range(1,x+1):
d.extend([d[i>>1]+(i&1)])
return d[x]
def readBinaryWatch(self, num):
"""
:type num: int
:rtype: List[str]
"""
dict={}
dict1={}
for x in range(13):
dict[x]=self.num_of_ones(x)
print(str(x)+" "+str(dict[x]))
for x in range(61):
dict1[x]=self.num_of_ones(x)
print(str(x)+" "+str(dict1[x]))
fin_d={}
out_list=[]
for h in range(0,13):
for m in range(61):
strr='%d:%.2d' % (h,m)
fin_d[strr]=dict[h]+dict1[m]
if(fin_d[strr]==num):
out_list.extend([strr])
return out_list
print(Solution().readBinaryWatch(2
))