[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 ...
随机推荐
- Linux使用netstat命令查看并发连接数[转]
转自:http://www.cnblogs.com/wayne173/p/5652043.html Linux使用netstat命令查看并发连接数 我们的网站部署在linux的服务器上,特别是we ...
- github快速入门(一)
一.github介绍 git是一款非常知名的代码托管工具.当然现在有了github for windows版本(类似于 svn tortoise). GitHub for Windows 是一个 Me ...
- Android studio插件安装
Android Studio安装插件的方式其实和Eclipse大同小异.废话不多说,直接上图: 区域1:你当前已经安装了的插件 区域2:在线安装 区域3:从硬盘安装,即针对你已经下载好了的插件,可通过 ...
- cocos2d 场景转换的方法执行顺序
转自:http://shanbei.info/the-cocos2d-scene-conversion-method-execution-order.html 如果你希望在场景转换的过程中使用过渡效果 ...
- Oracle12c功能增强 新特性之管理功能的增强
1. 数据文件在线重命名和迁移 不想先前的版本号.在Oracle12cR1中,数据文件的迁移或重命名不再要求一系列的步骤,比如:将表空间至于仅仅读模式,然后数据文件逻辑等操作.在12cR1中.数 ...
- WebService 设计总结
接触过非常多电商的WebService,有种一看就蛋疼的设计,今天要从这个反例说一说 WebService 的设计. [WebMethod] public string QueryOrderDetai ...
- 如何选择一个 Linux Tracer (2015)
http://www.oschina.net/translate/choosing-a-linux-tracer
- html5中viewport使用
html5中viewport使用 转载自:http://www.maoegg.com/the-usage-of-viewport-in-html5/ 用html5开发移动应用时往往会遇到手机的分辨率或 ...
- [MethodImpl(MethodImplOptions.Synchronized)]
在NopCommerce项目的Nop.Core类库中有一个EngineContext类中有一个Initialize方法用到了[MethodImpl(MethodImplOptions.Synchron ...
- 应聘.net开发工程师常见的面试题(四)
1.在Asp.net中所有的自定义用户控件都必须继承自________? 答:Control. 2.在.Net中所有可序列化的类都被标记为_____? 答:[serializable] 3.在.Net ...