191. Number of 1 Bits (Int; Bit)
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;
}
};
191. Number of 1 Bits (Int; Bit)的更多相关文章
- Leetcode#191. Number of 1 Bits(位1的个数)
题目描述 编写一个函数,输入是一个无符号整数,返回其二进制表达式中数字位数为 '1' 的个数(也被称为汉明重量). 示例 : 输入: 11 输出: 3 解释: 整数 11 的二进制表示为 000000 ...
- LN : leetcode 191 Number of 1 Bits
lc 191 Number of 1 Bits 191 Number of 1 Bits Write a function that takes an unsigned integer and ret ...
- LeetCode 191 Number of 1 Bits
Problem: Write a function that takes an unsigned integer and returns the number of '1' bits it has ( ...
- Java for LeetCode 191 Number of 1 Bits
Write a function that takes an unsigned integer and returns the number of ’1' bits it has (also know ...
- (easy)LeetCode 191.Number of 1 Bits
Number of 1 Bits Write a function that takes an unsigned integer and returns the number of ’1' bits ...
- Java [Leetcode 191]Number of 1 Bits
题目描述: Write a function that takes an unsigned integer and returns the number of ’1' bits it has (als ...
- 191. Number of 1 Bits
题目: Write a function that takes an unsigned integer and returns the number of ’1' bits it has (also ...
- 【LeetCode】191. Number of 1 Bits
题目: Write a function that takes an unsigned integer and returns the number of ’1' bits it has (also ...
- LeetCode 191. Number of 1 bits (位1的数量)
Write a function that takes an unsigned integer and returns the number of ’1' bits it has (also know ...
随机推荐
- jsp grid can not be used in this ('quirks') mode
设置: <!--设置IE文档模式 --> <meta http-equiv="X-UA-Compatible" content="IE=9" ...
- 【Linux】CentOS7 安装,遇到的各种问题,并修复win7启动项
https://www.cnblogs.com/sxdcgaq8080/p/7457255.html ------------------------------------------------- ...
- Spring BeanUtils简单使用
引入包 <dependency> <groupId>commons-beanutils</groupId> <artifactId>commons-be ...
- jquery实现增删改(伪)-老男孩作业day13
使用jquery进行,文件的编写,实现自增id,删除,添加,编辑模式. jquery放在本地,src="jquery_js.js" 可以改成其他,或者在线的路径 readme &l ...
- byobu session window split
new session: Ctrl + Shift + F2 window: F2 split: Shift/Ctrl + F2 move session: Alt + Up/Down window ...
- DOTWeen 使用
using UnityEngine; using System.Collections; using DG.Tweening; using UnityEngine.UI; public class T ...
- JSON数据的解析和生成(Swift)
Codable public typealias Codable = Decodable & Encodable public protocol Decodable {} public pro ...
- [CI]CodeIgniter应用配置明细
---------------------------------------------------------------------------------------------------- ...
- SimpleDateFormat 使用时出现的线程同步问题。。。
错误使用: public static final SimpleDateFormat DAY_UI_MONTH_DAY_FORMAT = new SimpleDateFormat("MM-d ...
- ArcMap导入图层出现General function failure问题 [转]
ArcMap导入图层出现General function failure问题 [转] Link: http://www.cnblogs.com/angelx/p/3391967.html 问题描述 ...