题目:

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 count = ;
while(n)
{
count++;
n = n & (n - );
}
return count;
}
};

Number of 1 Bits(Difficulty: Easy)的更多相关文章

  1. LeetCode算法题-Binary Number with Alternating Bits(Java实现)

    这是悦乐书的第292次更新,第310篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第160题(顺位题号是693).给定正整数,检查它是否具有交替位:即它的二进制数的任意两 ...

  2. LeetCode算法题-Number of 1 Bits(Java实现)

    这是悦乐书的第186次更新,第188篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第45题(顺位题号是191).编写一个带无符号整数的函数,并返回它所具有的"1 ...

  3. Counting Bits(Difficulty: Medium)

    题目: Given a non negative integer number num. For every numbers i in the range 0 ≤ i ≤ num calculate ...

  4. Power of Four(Difficulty: Easy)

    题目: Given an integer (signed 32 bits), write a function to check whether it is a power of 4. Example ...

  5. Integer Break(Difficulty: Easy)

    题目: Given a positive integer n, break it into the sum of at least two positive integers and maximize ...

  6. Leetcode#191. Number of 1 Bits(位1的个数)

    题目描述 编写一个函数,输入是一个无符号整数,返回其二进制表达式中数字位数为 '1' 的个数(也被称为汉明重量). 示例 : 输入: 11 输出: 3 解释: 整数 11 的二进制表示为 000000 ...

  7. hdu 4670 Cube number on a tree(点分治)

    Cube number on a tree Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/ ...

  8. A1082 Read Number in Chinese (25)(25 分)

    A1082 Read Number in Chinese (25)(25 分) Given an integer with no more than 9 digits, you are suppose ...

  9. 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 ...

随机推荐

  1. Deep Learning 23:dropout理解_之读论文“Improving neural networks by preventing co-adaptation of feature detectors”

    理论知识:Deep learning:四十一(Dropout简单理解).深度学习(二十二)Dropout浅层理解与实现.“Improving neural networks by preventing ...

  2. kali 安装FTP服务器-vsftpd

    参考文章:Ubuntu 14.04 FTP服务器--vsftpd的安装和配置 本文将会介绍在kali2.0上安装vsftpd,主要分成四块:更新源列表.安装和配置vsftpd服务器.使用ftp命令传输 ...

  3. JQuery_元素属性操作

    除了对元素内容进行设置和获取,通过jQuery 也可以对元素本身的属性进行操作,包括获取属性的属性值.设置属性的属性值,并且可以删除掉属性. <script type="text/ja ...

  4. [SoapUI] 在SoapUI里用Java语言判断Excel单元格为空或者Null时出错

    我取Excel数据时先判断cell是否为"": if(cellValue != ""){     listNumber.add(i);     cellValu ...

  5. TestNG中的数据源DataProvider概述

    http://blog.csdn.net/taiyangdao/article/details/52141711 在上一篇文章中,我们知道带参数的测试方法,可以在testng.xml配置文件中为其参数 ...

  6. Easy Sysprep更新日志-skyfree大神

    Easy Sysprep更新日志: Skyfree 发表于 2016-1-22 13:55:55 https://www.itsk.com/forum.php?mod=viewthread&t ...

  7. jQurey Plugin

    ; (function ($, window, document, undefined) { "use strict"; var defaults = { name: " ...

  8. PHP返回XML数据

    开发中经常会有用到XML格式数据的时候,那么用PHP怎么来将数组格式的数据用XML格式返回呢? 新建一个类文件,叫ArrayToXml.php <?php /** * 数组转XML类 * 使用方 ...

  9. jquery multiselect使用示例

    多选下拉框开源组件:https://github.com/ehynds/jquery-ui-multiselect-widget html部分: <select multiple id=&quo ...

  10. N 皇后问题

    #include <set> #include <iostream> #include <string> #include <vector> #incl ...