常德网站公司,做导航网站用什么源码,公司建设网站,wordpress免费家居主题1. 题目
二进制手表顶部有 4 个 LED 代表小时#xff08;0-11#xff09;#xff0c;底部的 6 个 LED 代表分钟#xff08;0-59#xff09;。
每个 LED 代表一个 0 或 1#xff0c;最低位在右侧。 例如#xff0c;上面的二进制手表读取 “3:25”。
给定一个非负整数 …1. 题目
二进制手表顶部有 4 个 LED 代表小时0-11底部的 6 个 LED 代表分钟0-59。
每个 LED 代表一个 0 或 1最低位在右侧。 例如上面的二进制手表读取 “3:25”。
给定一个非负整数 n 代表当前 LED 亮着的数量返回所有可能的时间。
案例:
输入: n 1
返回: [1:00, 2:00, 4:00, 8:00, 0:01, 0:02, 0:04, 0:08, 0:16, 0:32]注意事项:
输出的顺序没有要求。
小时不会以零开头比如 “01:00” 是不允许的应为 “1:00”。
分钟必须由两位数组成可能会以零开头比如 “10:2” 是无效的应为 “10:02”。来源力扣LeetCode 链接https://leetcode-cn.com/problems/binary-watch 著作权归领扣网络所有。商业转载请联系官方授权非商业转载请注明出处。
2. 解题
class Solution {vectorstring ans;int count;
public:vectorstring readBinaryWatch(int num) {int i, j;for(i 0; i 12; i){for(j 0; j 60; j){if(count1(i)count1(j) num)ans.push_back(to_string(i):(j10 ? (0to_string(j)) : to_string(j)));}}return ans;}int count1(int n)//计算二进制1的个数{count 0;while(n){n n(n-1);count;}return count;}
};