LeetCode题解:Number of 1 Bits
2015-08-26 20:27
316 查看
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的个数
解决思路:调API,或不断右移一位计数
代码:
For example, the 32-bit integer ’11’ has binary representation 00000000000000000000000000001011, so the function should return 3.
题意:求二进制字符串中1的个数
解决思路:调API,或不断右移一位计数
代码:
public class Solution { public int hammingWeight(int n) { return Integer.bitCount(n); } }
相关文章推荐
- Alice and Bob(贪心HDU 4268)
- 导入项目出现AppBaseTheme找不到的情况解决办法
- CF 168 B Zero Tree(树形dp)
- new、malloc和alloctor关系
- C++类型转换
- 数学模板 - 计算方法
- HTML5语言的28个新特性学习
- 面试题:升高的温度
- jquery学习——选择器
- MySql C++调用库Connector/c++编译 和 接口封装【一】mysql数据库安装
- LeetCode题解:House Robber
- HDU 5201 The Monkey King 组合数+不定方程解的个数
- android01-快速入门
- cocos2d js callfunc参数问题
- Xcode6中自动布局autolayout和sizeclass的使用
- iOS中枚举的定义
- loadrunner 日志
- ASP.NET Redis 开发 入门
- 不愿看到Java开发者再做的10件事
- fragment的使用和注意事项