[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 ...
随机推荐
- 关于Windows文件名和路径名的那些事
博客搬到了fresky.github.io - Dawei XU,请各位看官挪步.最新的一篇是:关于Windows文件名和路径名的那些事.
- 使用hexdump 查看二进制文件
国内私募机构九鼎控股打造APP,来就送 20元现金领取地址:http://jdb.jiudingcapital.com/phone.html 内部邀请码:C8E245J (不写邀请码,没有现金送) 国 ...
- 今天写一些 有关iOS 多图片组合 成一张图片的问题。保持原像素不变
1.要求:服务器给一张图片模板,要在模版上镂空,然后添加一些别的图片,然后组合成一张图,这个模版的像素 不是固定的,有可能比 当前手机屏幕大.所以,在组合截图的时候,有一定的要求. 贴代码: /** ...
- URL是否有效
unit Unit1;interfaceuses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, Syste ...
- 彻底解决android读取中文txt的乱码(自动判断文档类型并转码
原文:http://blog.csdn.net/handsomedylan/article/details/6138400 public String convertCodeAndGetText(St ...
- maven配置编译路径
在build标签下添加 <build> <sourceDirectory>src/main/java</sourceDirectory> <resources ...
- android129 zhihuibeijing 聊天机器人
上屏幕界面activity_main.xml: 语音识别界面 <LinearLayout xmlns:android="http://schemas.android.com/apk/r ...
- js源码保护
js的不可读化处理分为三个方面:压缩(compression).混淆(obfuscation) 和加密(encryption). (不可读化处理,这是我自己发明的术语,一切会增加代码不可读性的代码转换 ...
- debian非正常关机进不了图形界面的解决方法
昨天调试一个程序的时候,把界面设置成了POPUP方式,结果触发断点的时候,界面不能最小化,程序就死到那了,动不了,没办法只好按电源了,结果启动的时候提示 An automatic file syste ...
- How to Use Custom TTF Font on iOS
Cocos2d-x uses FontLabel to draw customer ttf font before v2.0.3(including v2.0.3). Now it uses UIFo ...