Backtracking-401. Binary Watch
A binary watch has 4 LEDs on the top which represent the hours (0-11), and the 6 LEDs on the bottom represent the minutes (0-59).
Each LED represents a zero or one, with the least significant bit on the right.

For example, the above binary watch reads "3:25".
Given a non-negative integer n which represents the number of LEDs that are currently on, return all possible times the watch could represent.
Example:
Input: n = 1
Return: ["1:00", "2:00", "4:00", "8:00", "0:01", "0:02", "0:04", "0:08", "0:16", "0:32"]
Note:
- The order of output does not matter.
- The hour must not contain a leading zero, for example "01:00" is not valid, it should be "1:00".
- The minute must be consist of two digits and may contain a leading zero, for example "10:2" is not valid, it should be "10:02".
class Solution {
public:
void DFS(int len, int k, int curIndex, int val, vector<int>& vec)
{
if(k== && len== && val < ) vec.push_back(val);
if(k== && len== && val < ) vec.push_back(val);
if(curIndex == len || k == ) return;
DFS(len, k, curIndex+, val, vec);
val += pow(, curIndex), k--, curIndex++;
DFS(len, k, curIndex, val, vec);
}
vector<string> readBinaryWatch(int num) {
vector<string> ans;
for(int i = max(, num-); i <= min(, num); i++)
{
vector<int> vec1, vec2;
DFS(, i, , , vec1), DFS(, num-i, , , vec2);
for(auto val1: vec1)
for(auto val2: vec2)
{
string str = (to_string(val2).size()==?"":"") + to_string(val2);
ans.push_back(to_string(val1)+":"+ str);
}
}
return ans;
}
};
Backtracking-401. Binary Watch的更多相关文章
- 401. Binary Watch
[题目] Total Accepted: 10330 Total Submissions: 24061 Difficulty: Easy Contributors: Admin A binary wa ...
- 27. leetcode 401. Binary Watch
A binary watch has 4 LEDs on the top which represent the hours (0-11), and the 6 LEDs on the bottom ...
- [LeetCode&Python] Problem 401. Binary Watch
A binary watch has 4 LEDs on the top which represent the hours (0-11), and the 6 LEDs on the bottom ...
- 401. Binary Watch 回溯
A binary watch has 4 LEDs on the top which represent the hours (0-11), and the 6 LEDs on the bottom ...
- [LeetCode] 401. Binary Watch 二进制表
A binary watch has 4 LEDs on the top which represent the hours (0-11), and the 6 LEDs on the bottom ...
- 【LeetCode】401. Binary Watch 解题报告(Java & Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 java解法 Python解法 日期 [LeetCo ...
- [leetcode] 401. Binary Watch
https://leetcode.com/contest/5/problems/binary-watch/ 这个题应该是这次最水的,这个题目就是二进制,然后是10位,最大1024,然后遍历,找二进制里 ...
- 401 Binary Watch 二进制手表
详见:https://leetcode.com/problems/binary-watch/description/ C++: class Solution { public: vector<s ...
- LeetCode_401. Binary Watch
401. Binary Watch Easy A binary watch has 4 LEDs on the top which represent the hours (0-11), and th ...
- LeetCode All in One 题目讲解汇总(持续更新中...)
终于将LeetCode的免费题刷完了,真是漫长的第一遍啊,估计很多题都忘的差不多了,这次开个题目汇总贴,并附上每道题目的解题连接,方便之后查阅吧~ 477 Total Hamming Distance ...
随机推荐
- laravel在控制器中赋值给视图
1.控制器 2.视图
- glog日志
google 开源日志库 #include <glog/logging.h> yum install glog
- Nginx详解(正向代理、反向代理、负载均衡原理)
Nginx配置详解 nginx概述 nginx是一款自由的.开源的.高性能的HTTP服务器和反向代理服务器:同时也是一个IMAP.POP3.SMTP代理服务器:nginx可以作为一个HTTP服务器进行 ...
- postman模拟登录接口
https://blog.csdn.net/qq_22219911/article/details/80235272
- 2018.10.18 NOIP训练 [SCOI2018]Pipi 酱的日常(线段树)
传送门 线段树好题啊. 题目要求的是sum−a−b−c+maxsum-a-b-c+maxsum−a−b−c+max{∣a+v∣+∣b+v∣+∣c+v∣|a+v|+|b+v|+|c+v|∣a+v∣+∣b ...
- 2018.07.10 NOIP模拟 sort(单调队列)
Sort 题目背景 SOURCE:NOIP2016-RZZ-4 T1 题目描述 给你一个长度为 n 的排列,小W每次可以选择一个数,做以下操作: 不断把这个数与它右边的数交换. 当它右边没有数,或它右 ...
- EF生成的SQL语句执行顺序问题。
//实体被更改后,再做删除,EF只生成删除语句 //实体删除后再更改,EF报错 //添加语句会再,更改,删除后执行,更AddObject位置无关 //一个实体多个字段被改,只会生成一句update / ...
- Mac pro 安装IntelliJ IDEA 2017版
1.官网下载这个版本https://www.jetbrains.com 2.点击下载即可 3.下载好后放入本地 4.启动mac终端进行破解 输入命令:sudo vim /private/etc/hos ...
- ansible api 调用出现ssh交互式输入
发现在删掉 ~/.ssh/know_hosts 之后运行 ansible api 会出现以下提示 The authenticity of host '10.1.*.* (10.1.*.*)' can' ...
- Mouse Touch Stylus
Mouse操作: preview mouse down, StylusDevice:null mouse down,StylusDevice:null preview mouse up, Stylus ...