I created a function called readBinaryWatch and for some reason when my num=2, I get an answer 1.15. After debugging for a long time, I still can't figure out why there is a 1:15 in my solution instead of a 1:16
When I put in the print statements as you can tell my h,m prints
1.08
1.0 0.08 8.0
['3:00', '5:00', '9:00', '1:01', '1:02', '1:04', '1:08']
1.16
1.0 0.16 16.0
['3:00', '5:00', '9:00', '1:01', '1:02', '1:04', '1:08', '1:15'] The question is where is this 1:15 coming from!?!??! Please help.
Here's the code
def readBinaryWatch(num):
"""
:type num: int
:rtype: List[str]
"""
time=[1,2,4,8,.01,.02,.04,.08,.16,.32]
def dfs(i,n,path):
if not n:
print path
h,m=divmod(path,1)
print h,m,m*100
ret.append('%d:%02d' % (h, m*100))
print ret
for j in xrange(i,len(time)):
dfs(j+1,n-1,path+time[j])
ret=[]
dfs(0,num,0)
return ret