Python | Leetcode Python题解之第401题二进制手表
题目:
题解:
class Solution:
def readBinaryWatch(self, turnedOn: int) -> List[str]:
ans = list()
for i in range(1024):
h, m = i >> 6, i & 0x3f # 用位运算取出高 4 位和低 6 位
if h < 12 and m < 60 and bin(i).count("1") == turnedOn:
ans.append(f"{h}:{m:02d}")
return ans