191 Number of 1 Bits
2015-08-04 11:20
295 查看
/*
* 32位无符号数最大为2147483647
* Java中没有无符号类型,所以此题不能用n%2的方法解题
*/
public class Solution {
// you need to treat n as an unsigned value
public int hammingWeight(int n) {
int bits = 0;
int t = 0;
while(n!=0){
bits += (n&1);
n = n >>> 1;
}
return bits;
}
}
* 32位无符号数最大为2147483647
* Java中没有无符号类型,所以此题不能用n%2的方法解题
*/
public class Solution {
// you need to treat n as an unsigned value
public int hammingWeight(int n) {
int bits = 0;
int t = 0;
while(n!=0){
bits += (n&1);
n = n >>> 1;
}
return bits;
}
}
相关文章推荐
- C语言undefined behaviour未定义行为
- 【c++】用string类定义字符串数组
- Spring常用jar包的剖析
- android .9.png ”点九” 图片制作方法
- Centos 下 mysql root 密码重置
- (转)Thinkphp系统常量 演示
- Next Permutation
- Let the Balloon Rise
- Rsync安装手册
- final....
- HTML5中的本地存储sessionStorage、localStorage、Web SQL Database
- Ubuntu下Eclipse无法正常启动问题解决
- 制造企业生产类型
- postgreSql导出数据库数据
- cocos2d-x 学习笔记之生成Android Apk文件
- apache kafka中server.properties配置文件参数说明
- poj-1575-Easier Done Than Said?
- 菜鸟总结so分析,arm 汇编,IDA静态分析
- HDU 2501 Tiling_easy version
- HDU--1394 Minimum Inversion Number