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;
}
};

最新文章

  1. git教程
  2. ASP.NET Aries 开源开发框架:开发指南(一)
  3. Oracle EBS进化史
  4. Atitit sql执行计划
  5. mysql之各种命令总结
  6. 配置Junit测试程序
  7. node socket onmessage
  8. 博弈论(男人八题):POJ 1740 A New Stone Game
  9. 使用EditText搜索listview里面的内容,实现Listview跟随变动的情况
  10. 探究Android中Listview显示错乱问题
  11. protected访问修饰符
  12. bat加载和分离VHD
  13. 微信支付.net官方坑太多,我们来精简
  14. Spring框架——IOC依赖注入
  15. nexus私服搭建及maven生命周期
  16. yum安装软件报错Segmentation fault处理
  17. 数据库语句收藏(MySQL)
  18. tomcat目录结构以及项目部署
  19. servlet中将值以json格式传入
  20. 【转】MFC 数据绑定 DoDataExchange( )

热门文章

  1. WPF 自定义鼠标光标
  2. 07-border(边框)
  3. 使用PHP的反射Reflection获取对象信息
  4. 2018SDIBT_国庆个人第五场
  5. RESET MASTER和RESET SLAVE使用场景和说明,以及清除主从同步关系
  6. Redis进阶实践之六Redis Desktop Manager连接Windows和Linux系统上的Redis服务(转载6)
  7. vue项目分辨率
  8. 判断页面是否添加了W3C声明
  9. Django使用自定义的authentication登录认证
  10. python技巧 显示对象的所有属性