191. Number of 1 Bits (Int; Bit)
2024-10-18 17:54:36
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.
class Solution {
public:
int hammingWeight(uint32_t n) {
int ret = ;
for (unsigned int i = ; i != ; i <<= ){
if(n & ) ret++;
n >>= ;
}
return ret;
}
};
最新文章
- git教程
- ASP.NET Aries 开源开发框架:开发指南(一)
- Oracle EBS进化史
- Atitit sql执行计划
- mysql之各种命令总结
- 配置Junit测试程序
- node socket onmessage
- 博弈论(男人八题):POJ 1740 A New Stone Game
- 使用EditText搜索listview里面的内容,实现Listview跟随变动的情况
- 探究Android中Listview显示错乱问题
- protected访问修饰符
- bat加载和分离VHD
- 微信支付.net官方坑太多,我们来精简
- Spring框架——IOC依赖注入
- nexus私服搭建及maven生命周期
- yum安装软件报错Segmentation fault处理
- 数据库语句收藏(MySQL)
- tomcat目录结构以及项目部署
- servlet中将值以json格式传入
- 【转】MFC 数据绑定 DoDataExchange( )