401. Binary Watch
Input: n = 1
Return: ["1:00", "2:00", "4:00", "8:00", "0:01", "0:02", "0:04", "0:08", "0:16", "0:32"]# @param {Integer} num
# @return {String[]}
def read_binary_watch(num)
output = []
(0..11).each do |h|
(0..59).each do |m|
if (h.to_s(2) + m.to_s(2)).count('1') == num
output << "#{h}:#{sprintf("%02d",m)}"
end
end
end
output
endLast updated
