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的更多相关文章

  1. 401. Binary Watch

    [题目] Total Accepted: 10330 Total Submissions: 24061 Difficulty: Easy Contributors: Admin A binary wa ...

  2. 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 ...

  3. [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 ...

  4. 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 ...

  5. [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 ...

  6. 【LeetCode】401. Binary Watch 解题报告(Java & Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 java解法 Python解法 日期 [LeetCo ...

  7. [leetcode] 401. Binary Watch

    https://leetcode.com/contest/5/problems/binary-watch/ 这个题应该是这次最水的,这个题目就是二进制,然后是10位,最大1024,然后遍历,找二进制里 ...

  8. 401 Binary Watch 二进制手表

    详见:https://leetcode.com/problems/binary-watch/description/ C++: class Solution { public: vector<s ...

  9. 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 ...

  10. LeetCode All in One 题目讲解汇总(持续更新中...)

    终于将LeetCode的免费题刷完了,真是漫长的第一遍啊,估计很多题都忘的差不多了,这次开个题目汇总贴,并附上每道题目的解题连接,方便之后查阅吧~ 477 Total Hamming Distance ...

随机推荐

  1. [NOI.AC]COUNT(数学)

    解析: 也可以将所有的可能都计算出来,后进行减法运算. 代码: #include<bits/stdc++.h> using namespace std; #define ll long l ...

  2. 680C. Bear and Prime 100 数学

    C. Bear and Prime 100 time limit per test:1 second memory limit per test:256 megabytes input:standar ...

  3. 使用 Php Artisan Tinker 来调试你的 Laravel

    Posted on 2016年6月19日 by ichou 本文翻译自:Tinker with the Data in Your Laravel Apps with Php Artisan Tinke ...

  4. 创建一个子进程---vfork

    子.父进程共享数据段与堆栈段 函数原型:pid_t vfork(void) 返回值:子进程中返回0,父进程中返回子进程ID,出错返回-1. 注意: vfork创建的进程是按先子进程后父进程的顺序执行的 ...

  5. linux下集成开发环境之ECLIPSE--在线调试、编译程序

    裸机开发流程 1.编写裸机程序:2.调试裸机程序:3.生成2进制映象(编译.链接.格式转换):4.烧写/运行2进制映象. 注意:我们自己开发的程序等等需要下载到开发板的Nandflash(类似于硬盘功 ...

  6. C++11的一般概念——The C++ standard library, 2nd Edition 笔记(二)

    ( 原书第四章,General Concepts) 只介绍新内容,关于头文件格式和后缀等C++03已经规范化的内容,不再赘述. namespace std:新的std子空间包括: std::tr1, ...

  7. [转载红鱼儿]Delphi XE7 update1进步太大了

    写以下的文字是怀着无比兴奋的心情写的,急于同朋友们分享XE7的进步! 1.更新的bug列表并不全 通过bug修正列表及发布的消息,可以看到up1修正了很多bug,正如我所说,有些bug并没有写到发布的 ...

  8. Netty学习第一节Netty的总体概况

    一.Netty简介 什么是Netty? 1.高性能事件驱动,异步非阻塞的IO加载开源框架. 它是由JBoss提供,用于建立TCP等底层链接.基于Netty可以建立高性能的HTTP服务器,快速开发高性能 ...

  9. [笔记]python

    配置python apt install python2.7 python3 apt install python-bs4 python3-bs4 apt install virtualenv apt ...

  10. ubuntu 14.04查看java的安装路径

    有时候,使用apt-get install 安装了某个软件之后,却不知道这个软件的安装路径在哪里. 那怎么样去找出这个软件的安装路径呢? 下面我们java 这个软件为例, 找出ubuntu 14.04 ...