diff options
author | Jack Sangdahl <[email protected]> | 2025-03-12 13:37:35 -0600 |
---|---|---|
committer | Jack Sangdahl <[email protected]> | 2025-03-12 13:37:35 -0600 |
commit | c4e135086dbef6281031947b44cab3379afe404e (patch) | |
tree | 02402cbbb3454836f4d2c494b2becaa8070a170e /binary_watch.py | |
parent | b477c5d538f1fef91dbf906a17411eef32b2ded2 (diff) | |
download | leetcode-c4e135086dbef6281031947b44cab3379afe404e.tar.gz leetcode-c4e135086dbef6281031947b44cab3379afe404e.zip |
401. binary watch
Diffstat (limited to 'binary_watch.py')
-rw-r--r-- | binary_watch.py | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/binary_watch.py b/binary_watch.py new file mode 100644 index 0000000..f7af950 --- /dev/null +++ b/binary_watch.py @@ -0,0 +1,30 @@ +# 401. Binary Watch + +""" +a binary watch has 4 leds on the top to represent the hours (0 - 11) and 6 +leds on the bottom to represent the minutes (0 - 59). each led represents a 0 +or one, with the least siginificant bit on the right. given an integer +'turnedOn' which represents the number of leds that are currently on, return +all possible times the watch could represent. you may return the answer in +any order. +""" + + +class Solution(object): + def readBinaryWatch(self, turnedOn): + """ + :type turnedOn: int + :rtype: List[str] + """ + return [ + "%d:%02d" % (h, m) + for h in range(12) + for m in range(60) + if (bin(h) + bin(m)).count("1") == turnedOn + ] + + +if __name__ == "__main__": + obj = Solution() + print(obj.readBinaryWatch(turnedOn=1)) + print(obj.readBinaryWatch(turnedOn=9)) |