Leetcode Number of 1 Bits 191
来源:互联网 发布:手机上能装修淘宝店铺 编辑:程序博客网 时间:2024/06/05 04:10
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.
判断无符号数的1的个数
public class Solution {
// you need to treat n as an unsigned value
public int hammingWeight(int n) {
int count = 0;
while(n!=0){
n=n&(n-1);
count++;
}
return count;
}
}
0 0
- leetcode:bits:Number of 1 Bits(191)
- [Leetcode 191, Easy] Number of 1 Bits
- leetCode #191 number of 1 bits
- LeetCode 191 Number of 1 Bits
- Leetcode NO.191 Number of 1 Bits
- [LeetCode][191][Number of 1 Bits]
- [leetcode 191]Number of 1 Bits
- LeetCode(191) Number of 1 Bits
- LeetCode #191 Number of 1 Bits
- LeetCode 191: Number of 1 Bits
- LeetCode 191 Number of 1 Bits
- Leetcode #191 Number of 1 Bits
- LeetCode 191 Number of 1 Bits
- LeetCode 191: Number of 1 Bits
- leetcode[191]:Number of 1 Bits
- leetcode-191-Number of 1 Bits
- leetcode 191:Number of 1 Bits
- leetcode: (191) Number of 1 Bits
- 项目管理 hdoj 4858 (vector初学)
- 【LeetCode】LeetCode——第15题:3Sum
- Webview访问移动网络的两种方法
- poj 3080 Blue Jeans
- hive启动失败的小问题总结以及hive
- Leetcode Number of 1 Bits 191
- 欢迎使用CSDN-markdown编辑器
- Spring与Quartz的整合实现定时任务调度
- 练习题c++(一)
- java文件拷贝类
- 一分钟教你用Chrome的RSS来订阅博客
- 文本文件格式浅析以及转换
- 在Unity中StartCoroutine/yield return这个模式到底是怎么应用的?其中的原理是什么?
- MySQL 中的数据类型介绍