1 Star 0 Fork 0

表情扭曲 / leetcode

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
lc191.java 470 Bytes
一键复制 编辑 原始数据 按行查看 历史
liu13 提交于 2019-02-25 09:54 . 20190225
package code;
/*
* 191. Number of 1 Bits
* 题意:统计二进制数中1的个数
* 难度:Easy
* 分类:Bit Manipulation
* 思路:每次移一位,与运算
* Tips:
*/
public class lc191 {
// you need to treat n as an unsigned value
public int hammingWeight(int n) {
int sum = 0;
int a = 1;
while(a!=0){
int b = n&a;
if(b!=0) sum += 1;
a <<= 1;
}
return sum;
}
}
1
https://gitee.com/abfantasy/leetcode.git
git@gitee.com:abfantasy/leetcode.git
abfantasy
leetcode
leetcode
master

搜索帮助