LeeCode-Number of 1 Bits
2016-04-25 18:48
232 查看
Write a function that takes an unsigned integer and returns the number of ’1' bits it has For example, the 32-bit integer ’11' has binary representation 00000000000000000000000000001011,so the function
should return 3.
int hammingWeight(uint32_t n)
{
int count=0;
while(n)
{
n=n&(n-1);
count++;
}
return count;
}
should return 3.
int hammingWeight(uint32_t n)
{
int count=0;
while(n)
{
n=n&(n-1);
count++;
}
return count;
}
相关文章推荐
- 去掉listview的item点击时候的背景颜色
- undefined reference to 'socket@12'编译socket出错codeblocks
- Android中深入理解 LayoutInflater.inflate()
- 删除mysql的root用户,重建本地用户及远程用户
- 宋浒智:风华一代总统换届 汇市巨震避险不安
- JVM调优总结 -Xms -Xmx -Xmn -Xss
- head用法
- js随笔,css和js禁止网页选择文本,table的class样式使得td的class样式失效,jquery获得元素坐标
- iOS启动动画
- hdoj1012
- 分治算法-归并排序
- CSS颜色值,长度值
- 2016年04月19日
- (水平,竖直)导航菜单制作
- JavaScript入门学习1
- JavaScript入门学习2
- JavaScript入门学习3;基本用法
- JavaScript入门学习4
- JavaScript入门学习5 DOM操作1
- CSS 3 的动画功能