191. Number of 1 Bits
2016-03-10 15:42
288 查看
Write a function that takes an unsigned integer and returns the number of ’1’ bits it has (also known as the Hamming weight).
For example, the 32-bit integer ’11’ has binary representation 00000000000000000000000000001011, so the function should return 3.
For example, the 32-bit integer ’11’ has binary representation 00000000000000000000000000001011, so the function should return 3.
class Solution { public: int hammingWeight(uint32_t n) { int count = 0; while(n) { ++ count; n = n & (n - 1); } return count; } };
相关文章推荐
- Mysql查找如何判断字段是否包含某个字符串
- pcl 1.8.0(5) VTK编译
- mysqlcppconn之ConnectOptionsMap的使用
- 联系苹果必备!App Store官方邮箱列表大全
- 用NSFileManager实现文件夹占内存计算
- Flex 布局教程:语法篇
- ID3决策树的Java实现
- 利用 CURL 发送JSON格式字符串
- Dynamics CRM The difference between UserId and InitiatingUserId in Plugin
- iOS 【automaticallyAdjustsScrollViewInsets 属性介绍】
- sqlserver,oracle,mysql等的driver驱动,url怎么写
- 关于dispatch_semaphore的使用
- Android的animation动画
- centOS 7 安装 MySQL5.7.11
- 深入理解hadoop(一)
- Dynamics CRM The difference between UserId and InitiatingUserId in Plugin
- Dynamics CRM The difference between UserId and InitiatingUserId in Plugin
- Dynamics CRM The difference between UserId and InitiatingUserId in Plugin
- Linux学习笔记:压缩解压命令
- 高并发的关注点