您的位置:首页 > 房产 > 建筑 > 工业产品设计公司排名_国内b2b网站a片_今日疫情最新消息_做网站需要哪些技术

工业产品设计公司排名_国内b2b网站a片_今日疫情最新消息_做网站需要哪些技术

2025/1/25 8:40:35 来源:https://blog.csdn.net/mobius_strip/article/details/142891986  浏览:    关键词:工业产品设计公司排名_国内b2b网站a片_今日疫情最新消息_做网站需要哪些技术
工业产品设计公司排名_国内b2b网站a片_今日疫情最新消息_做网站需要哪些技术

Problem

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 zero or one, with the least significant bit on the right.

Given an integer turnedOn which represents the number of LEDs that are currently on (ignoring the PM), return all possible times the watch could represent. You may return the answer in any order.

The hour must not contain a leading zero.

  • For example, “01:00” is not valid. It should be “1:00”.

The minute must consist of two digits and may contain a leading zero.

  • For example, “10:2” is not valid. It should be “10:02”.

Algorithm

Count the state of the LED and sum them in hours and minutes.

Code

class Solution:def readBinaryWatch(self, turnedOn: int) -> List[str]:hours_minutes = [8, 4, 2, 1, 32, 16, 8, 4, 2, 1] # 4 + 6buf = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]ans = []def dfs(n, s):if not n:h, m = 0, 0for i in range(4):h += hours_minutes[i] * buf[i]for i in range(4, 10):m += hours_minutes[i] * buf[i]if h >= 0 and h <= 11 and m >= 0 and m <= 59:ans.append(str(h)+":"+str(m//10)+str(m%10))returnelse:for i in range(s, 10):buf[i] = 1dfs(n-1, i+1)buf[i] = 0dfs(turnedOn, 0)return ans

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com