401. Binary Watch

Easy

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".
package leetcode.easy;

public class BinaryWatch {
public java.util.List<String> readBinaryWatch(int num) {
java.util.List<String> ret = new java.util.ArrayList<>(1024); for (int hour = 0; hour < 12; ++hour) {
for (int min = 0; min < 60; ++min) {
if (Integer.bitCount(hour) + Integer.bitCount(min) == num) {
ret.add(String.format("%d:%02d", hour, min));
}
}
} return ret;
} @org.junit.Test
public void test() {
System.out.println(readBinaryWatch(1));
}
}

最新文章

  1. 转:android异步任务设计思详解(AsyncTask)
  2. JavaScript学习基础篇【第1篇】: JavaScript 入门
  3. Android获取ROOT权限
  4. oracle应该安装在什么版本的linux下
  5. myeclipse自动排版
  6. 发布订阅 - 基于A2DFramework的事件机制实现
  7. &lt;转&gt;单播,广播,组播的缺点与优点
  8. C++中的class
  9. Bitbucket导入项目
  10. hdu5673 Robot 卡特兰数 / 默慈金数
  11. 图文详解AO打印(端桥模式)
  12. JS学习笔记Day12
  13. Judy Beta Postmortem
  14. spring jdbctemplate调用存储过程,返回list对象
  15. 关于DDR3控制器的使用
  16. Python【每日一问】04
  17. BZOJ 2039 [2009国家集训队]employ人员雇佣 网络流
  18. word 2013 自动保存太慢,下面读条起码3分钟
  19. docker 安装vim
  20. 20145318《网络对抗》逆向及Bof基础

热门文章

  1. linux 中截取字符串
  2. 常见的C语言编程规范
  3. 依赖注入(DI)和控制反转(IOC)
  4. house买房原理,2019,第一版
  5. Go读写文件
  6. ashx 图片上传路径URL
  7. 洛谷 P1082 同余方程 题解
  8. C# CRC16校验码 1.0
  9. LIO -SCSI target
  10. 关于Ubuntu中snap安装软件太慢解决办法