Write a function that takes an unsigned integer and returns the number of ’1' bits it has

For example, the 32-bit integer ’11' has binary representation 00000000000000000000000000001011,

so the function should return 3.

 int hammingWeight(uint32_t n)
{
int count=;
while(n)
{
n=n&(n-);
count++;
}
return count;
}

LeeCode-Number of 1 Bits的更多相关文章

  1. [LeetCode] Number of 1 Bits 位1的个数

    Write a function that takes an unsigned integer and returns the number of ’1' bits it has (also know ...

  2. 【leetcode】Number of 1 Bits

    题目描述: Write a function that takes an unsigned integer and returns the number of '1' bits it has (als ...

  3. Number of 1 Bits(Difficulty: Easy)

    题目: Write a function that takes an unsigned integer and returns the number of ’1' bits it has (also ...

  4. LeetCode 191 Number of 1 Bits

    Problem: Write a function that takes an unsigned integer and returns the number of '1' bits it has ( ...

  5. LeetCode Number of 1 Bits

    原题链接在这里:https://leetcode.com/problems/number-of-1-bits/ 题目: Write a function that takes an unsigned ...

  6. leetCode191/201/202/136 -Number of 1 Bits/Bitwise AND of Numbers Range/Happy Number/Single Number

    一:Number of 1 Bits 题目: Write a function that takes an unsigned integer and returns the number of '1' ...

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

  8. (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 ...

  9. leetcode:Number of 1 Bits

    Write a function that takes an unsigned integer and returns the number of ’1' bits it has (also know ...

  10. 【LeetCode】190 & 191 - Reverse Bits & Number of 1 Bits

    190 - Reverse Bits Reverse bits of a given 32 bits unsigned integer. For example, given input 432615 ...

随机推荐

  1. Hadoop 写SequenceFile文件 源代码

    package com.tdxx.hadoop.sequencefile; import java.io.IOException; import org.apache.hadoop.conf.Conf ...

  2. web项目的两个创建形式website和webapplication

    前言 在利用VS2010创建web项目的时候,会有两个选择.可以选择直接创建website网站,还可以选择使用 webapplication应用程序.刚刚接触web开发,看到这两个就疑惑了,既然是都可 ...

  3. C基础知识小总结(十)

                  "如有不正确之处,请指出,谢谢"    --Mood   <指针和函数> 指针函数   函数指针 <最基本的使用函数指针>   ...

  4. 【HDU】 1018 Big Number

    大意就是求 : log10(n!) = log10(1 * 2 *  3 * .......*n) = log10(1) + log10(2) + ........+log10(n); 打表的话会ML ...

  5. js获取名字为XX的标签

    $("input[name='XX']"); <input name="address_select" type="radio" va ...

  6. input输入字母自动大小写转换

    <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content ...

  7. [跟我学Spring学习笔记][DI配置与使用]

    DI 依赖和依赖注入 定义 传统的依赖一般指"类之间的关系",那先让我们复习一下类之间的关系: 泛化:表示类与类之间的继承关系.接口与接口之间的继承关系: 实现:表示类对接口的实现 ...

  8. java public protect default private

    (1)对于public修饰符,它具有最大的访问权限,可以访问任何一个在CLASSPATH下的类.接口.异常等.它往往用于对外的情况,也就是对象或类对外的一种接口的形式. (2)对于protected修 ...

  9. JavaScript ----------- 组合继承

    继承 实现继承:继承实际的方法.ECMAScript 只支持实现继承,而且其实现基础主要是依靠原型链来实现的. 基本思想是:利用原型来实现一个引用类型继承另外一个引用类型的属性和方法. 原型 - 构造 ...

  10. c# 调用 友盟api

    今天要使用友盟的推送API来给我的app进行推送信息,调试了好久,老是返回500错误,最终在友盟的技术人员支持下完成了此操作,在此多谢友盟技术和客服人员. 把发方法和注意事项贴出来供大家参考. pub ...