Count 1 in Binary
Count how many 1 in binary representation of a 32-bit integer.
Given 32, return 1
Given 5, return 2
Given 1023, return 9
public class Solution {
/**
* @param num: an integer
* @return: an integer, the number of ones in num
*/
public int countOnes(int num) {
int count = ;
for (int i = ; i <= ; i++) {
if ((num & ) == ) {
count++;
}
num = (num >> );
}
return count;
}
};
Count 1 in Binary的更多相关文章
- 365. Count 1 in Binary【LintCode java】
Description Count how many 1 in binary representation of a 32-bit integer. Example Given 32, return ...
- lintcode :Count 1 in Binary 二进制中有多少个1
题目: 二进制中有多少个1 49% 通过 计算在一个 32 位的整数的二进制表式中有多少个 1. 样例 给定 32 (100000),返回 1 给定 5 (101),返回 2 给定 1023 (111 ...
- LintCode Count 1 in Binary
知识点 1. 整数的二进制表示法 2. 十进制和二进制的转换 http://baike.baidu.com/view/1426817.htm 3. 负整数的表示(原码,补码,反码) http://ww ...
- Binary to Text (ASCII) Conversion
Binary to Text (ASCII) Conversion Description: Write a function that takes in a binary string and re ...
- [LintCode]——目录
Yet Another Source Code for LintCode Current Status : 232AC / 289ALL in Language C++, Up to date (20 ...
- OpenSSLKey
http://www.jensign.com/opensslkey/opensslkey.cs //************************************************** ...
- 二维码详解(QR Code)
作者:王子旭链接:https://zhuanlan.zhihu.com/p/21463650来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注明出处. 2016.7.5 更新:长文 ...
- 求最大连续bit数
描述 功能: 求一个byte数字对应的二进制数字中1的最大连续数,例如3的二进制为00000011,最大连续2个1 输入: 一个byte型的数字 输出: 无 返回: 对应的二进制数 ...
- Erlang 103 Erlang分布式编程
Outline 笔记系列 Erlang环境和顺序编程Erlang并发编程Erlang分布式编程YawsErlang/OTP 日期 变更说明 2014-11-23 A Outl ...
随机推荐
- 【题解】JSOI2009球队收益 / 球队预算
为什么大家都不写把输的场次增加的呢?我一定要让大家知道,这并没有什么关系~所以 \(C[i] <= D[i]\) 的条件就是来卖萌哒?? #include <bits/stdc++.h&g ...
- div + css 样式连接
外部文件连接:<link rel ="stylesheet" type=""text/css" href="demo.css" ...
- SDOI2017遗忘的集合
题面链接 咕咕咕 题外话 为了这道题我敲了\(MTT\).多项式求逆.多项式\(ln\)等模板,搞了将近一天. sol 最近懒得写题解啊,随便搞搞吧. 看到这个就是生成函数套上去. \[F(x)=\p ...
- 【bzoj3209】 花神的数论题
http://www.lydsy.com/JudgeOnline/problem.php?id=3209 (题目链接) 题意 ${sum(i)}$表示${i}$的二进制表示中${1}$的个数.求${\ ...
- Linux及安全实践二——模块
Linux及安全实践二--模块 一.模块的编译.生成.测试.删除 1.编写模块代码 编写:gedit 3.c 2.编写Makefile obj-m :这个变量是指定你要声称哪些模块模块的格式为 obj ...
- 单点登录(八)-----遇到问题-----Application Not Authorized to Use CAS
配置好cas后访问cas client 并没有跳转到登录页面,而是页面报错误提示: Application Not Authorized to Use CAS. The application yo ...
- MySQL总结小妙招
mysql5.7版本,免登陆修改管理员密码: vim /etc/my.cnf 加入skip-grant-tables,重启MySQL 终端输入 mysql ,直接登录MySQL数据库,然后use my ...
- HEOI 2017 游记
HEOI2017也算是落下帷幕了,那就写一篇 流水账 游记好了. DAY 0 又是熟悉的大学,又是熟悉的机房 YD宾馆的房间依旧破的不行. 晚上在房间颓颓颓....=.= DAY 1 上午去试机,唯一 ...
- C++ std::allocator<T> 与new对比效率使用
基础知识通道:http://blog.csdn.net/Xiejingfa/article/details/50955295 C/C++: #include <iostream> #inc ...
- 01 C++ 多线程入门实例
1.可复用的完整实例 #include <iostream> #include <thread> #include <mutex> using namespace ...