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

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

  2. [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 199 :Binary Tree Right Side View

    // 我的代码 package Leetcode; /** * 199. Binary Tree Right Side View * address: https://leetcode.com/pro ...

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

  5. LeetCode:Unique Binary Search Trees I II

    LeetCode:Unique Binary Search Trees Given n, how many structurally unique BST's (binary search trees ...

  6. LeetCode: Validata Binary Search Tree

    LeetCode: Validata Binary Search Tree Given a binary tree, determine if it is a valid binary search ...

  7. (二叉树 递归) leetcode 145. Binary Tree Postorder Traversal

    Given a binary tree, return the postorder traversal of its nodes' values. Example: Input: [1,null,2, ...

  8. 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 这个题实际上就是把每一行最右侧的树打印出来,所以实际上还是一个层次遍历. 依旧利用之前层次遍历的代码,每次大的循环存 ...

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

随机推荐

  1. byte数组和int互转

    import java.nio.ByteBuffer; public class Program { public static void main(String[] args) { ByteBuff ...

  2. 局部更新listview的问题(只更新某个item)

    转:http://blog.csdn.net/wu_shu_jun/article/details/7794576 public void updateView(int itemIndex) { // ...

  3. ios十进制、十六进制字符串,byte,data等之间的转换

    十进制->十六进制 Byte bytes[]={0xA6,0x27,0x0A}; NSString *strIdL  = [NSStringstringWithFormat:@"%@& ...

  4. Android ListView快速定位(一)

    方法一: SectionIndexer接口 + 索引列表 参考:http://www.apkbus.com/android-69999-1-1.html 所谓section 就是一组有共性的item, ...

  5. Retina屏下1px border

    layout tltle tags post ios7下移动web开发的几个坑 webapp 1.Retina屏下1px border 由于高清屏的特性,1px是由2×2个像素点来渲染,那么我们样式上 ...

  6. [000]socket通信--server和client实现的简单例子

    在C语言中就学过scanf和printf,其实理解socket就跟这两个输入输出差不多,只不过是信息的传输而已. 1.TCP服务器端(server)的默认函数调用顺序: 按照上述的调用顺序,我们可以来 ...

  7. 根据字符串计算UILabel尺寸

    iOS开发中经常会遇到UILabel大小尺寸不固定的情况,需要根据文字内容变化,这时候就需要计算文字大小以自动改变UILabel的尺寸. iOS7之后计算尺寸只需要一个方法就可以: - (CGSize ...

  8. MySQL(16):Select-union(联合查询)

    1. Select-union(联合查询) union用于把来自许多SELECT语句的结果组合到一个结果集合中. 用法: SELECT ...UNION [ALL | DISTINCT]SELECT ...

  9. the first assignment of software testing

    Github ID:  bzdwdmzjsmff Github address: https://github.com/bzdwdmzjsmff alternative article: Increa ...

  10. 深入理解计算机系统第二版习题解答CSAPP 2.17

    假设w=4,我们能给每个可能的十六进制数字赋予一个数值,假设用一个无符号或者补码表示.完成下表: x 无符号(B2U(x)) 补码(B2T(x)) 十六进制 二进制 0xE 1110 14 -2 0x ...