[leetcode] 401. Binary Watch
https://leetcode.com/contest/5/problems/binary-watch/
这个题应该是这次最水的,这个题目就是二进制,然后是10位,最大1024,然后遍历,找二进制里面1的个数为满足要求的,然后判断是否超限,题目说的很清楚,小时0到11,分钟0到59,然后转化成要求的格式就行了。
class Solution {
public:
vector<string> work(int k) {
vector<string> res;
if(k > ) return res;
for (int i = ; i < ( << ); i++) {
if(__builtin_popcount(i) == k) {
int h = i >> ;
if(h > ) continue;
int m = i & (( << ) - );
if(m > ) continue;
stringstream ss;
ss << h; ss << ":";
if(m < ) ss << "";
ss << m;
string x = ss.str();
//cout << x << endl;
res.push_back(x);
}
}
return res;
}
vector<string> readBinaryWatch(int num) {
return work(num);
}
};
[leetcode] 401. Binary Watch的更多相关文章
- 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] 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 199 :Binary Tree Right Side View
// 我的代码 package Leetcode; /** * 199. Binary Tree Right Side View * address: https://leetcode.com/pro ...
- LeetCode:Construct Binary Tree from Inorder and Postorder Traversal,Construct Binary Tree from Preorder and Inorder Traversal
LeetCode:Construct Binary Tree from Inorder and Postorder Traversal Given inorder and postorder trav ...
- LeetCode:Unique Binary Search Trees I II
LeetCode:Unique Binary Search Trees Given n, how many structurally unique BST's (binary search trees ...
- LeetCode: Validata Binary Search Tree
LeetCode: Validata Binary Search Tree Given a binary tree, determine if it is a valid binary search ...
- (二叉树 递归) leetcode 145. Binary Tree Postorder Traversal
Given a binary tree, return the postorder traversal of its nodes' values. Example: Input: [1,null,2, ...
- leetcode 199. Binary Tree Right Side View 、leetcode 116. Populating Next Right Pointers in Each Node 、117. Populating Next Right Pointers in Each Node II
leetcode 199. Binary Tree Right Side View 这个题实际上就是把每一行最右侧的树打印出来,所以实际上还是一个层次遍历. 依旧利用之前层次遍历的代码,每次大的循环存 ...
- [LeetCode] 549. Binary Tree Longest Consecutive Sequence II_ Medium tag: DFS recursive
Given a binary tree, you need to find the length of Longest Consecutive Path in Binary Tree. Especia ...
随机推荐
- C#-设置窗体在显示器居中显示
在窗体的属性中查看:StartPosition属性,该属性的设置中有一个"CenterScreen"的选择项,该项就是设置窗体局中显示的.
- SQL索引详解
转自:http://www.cnblogs.com/AK2012/archive/2013/01/04/2844283.html SQL索引在数据库优化中占有一个非常大的比例, 一个好的索引的设计,可 ...
- [Javascript] Webpack Loaders, Source Maps, and ES6
Using ES6 To use ES6, we need loader. Modify webpack.config.js file: module.exports = { entry: './in ...
- 【机器学习算法-python实现】svm支持向量机(1)—理论知识介绍
(转载请注明出处:http://blog.csdn.net/buptgshengod) 1.背景 强烈推荐阅读(http://www.cnblogs.com/jerrylead/archiv ...
- 使用Twisted进行socket编程
你的协议处理类通常是twisted.internet.protocol.Protocol的子类.许多协议处理继承于该类或者比该类更加方便的该类的子类.一个protocol类的实例可能反复连接,也可能在 ...
- codereview介绍
1. 定义: Code review is systematic examination (often known as peer review) of computer source code. I ...
- mac mysql error You must reset your password using ALTER USER statement before executing this statement.
安装完mysql 之后,登陆以后,不管运行任何命令,总是提示这个 step 1: SET PASSWORD = PASSWORD('your new password'); step 2: ALTER ...
- deepin linux安装与配置
作者:相思羽 出处:http://www.cnblogs.com/xiang-siyu 欢迎转载,也请保留这段声明.谢谢! deepin linux是由深度开发的操作系统,基于debian,内置了搜 ...
- [wordpress]后台自定义菜单字段和使用wordpress color picker
Wordpress Version 4.4.2 参考链接 插件使用wordpress color picker:Add A New Color Picker To WordPress 后台菜单自定义字 ...
- Jquery 实现Xml文件内容处理
用JS对XMl文件处理实现和用JS处理一般的Dom元素一样; 加载一个Xml内容与新建一个Dom元素基本相同 如: 1.新建一个Dom元素的Jquey语法为:$("<p>hell ...