python using itertools to find combinations


  • 0
    J
        def readBinaryWatch(self, num):
            group = [0,1,2,3,4,5,6,7,8,9]
            import itertools
            time_seq = []
            for c in list(itertools.combinations(group,num)):
                seq = '0000000000'
                for i in c:
                    seq = seq[:i] + '1' + seq[i+1:]
                if int(seq[:4],2)<12 and int(seq[4:],2)<60:
                    time_seq.append(str(int(seq[:4],2)) +':'+str(int(seq[4:],2)).zfill(2))
            return time_seq```

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.