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)的更多相关文章

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

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

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

  3. LeetCode 191 Number of 1 Bits

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

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

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

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

  7. 191. Number of 1 Bits

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

  8. 【LeetCode】191. Number of 1 Bits

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

  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. ubuntu-14.04中/boot分区不足的解决办法

    环境:ubuntu-kylin 或者 ubuntu-14.04,/boot单独分区工具:ubuntu的liveCD. 问题: 由于当初安装的时候,看网上说/boot很小,100M足以,于是单独分区,分 ...

  2. 判断窗体 show完成

    TForm窗体 this->Visible           this->Showing        true: 显示 fale:关闭     这个可用    this->Act ...

  3. iOS多语言

    https://blog.csdn.net/huangmindong/article/details/53464334 App多语言,字符串统一放在 Localizable.strings 文件里. ...

  4. iOS 视图间的几种通信方式

    注:此处视图为广义上的视图,不限于View,ViewController之类的都算. 大致分为三种,Notification, delegate, block 例: 假设要在A视图中调起B视图,B视图 ...

  5. shell编程小技巧(命令篇)

    本文主要介绍shell编程中一些好用的命令或者一些常见命令但比较少用却又好用的参数,目的是希望可以提高编码效率. df命令 常用命令 df / df -k / df -m / df -H / df - ...

  6. Android事件拦截机制 - 两句话

    模拟情形:ViewGroupA ->ViewGroupB->View False往下走,True就停下.(适用于事件传递和事件处理)

  7. jQuery添加添加时间与时间戳相互转换组件

    时间与时间戳的格式相互转换(转换主要兼容ie8,ie8不支持new Date()) (function($) { $.extend({ myTime: { CurTime: function () { ...

  8. 30.SSH配置文件模板和类库.md

    目录 1.struts2 4.类库 1.struts2 1.<?xml version="1.0" encoding="UTF-8"?>2.< ...

  9. week06 09 NodeJS Server as a RPCclient - jayson

    nodeserver端的rpcclient 来调用后端backendserver端定义的add等方法 2个server连通 Make NodeJs as a client - Npm jayson 用 ...

  10. 学JS的心路历程 - PixiJS -基础(一)

    建立canvas 今天开始我们一步步来看怎么使用PixiJS吧! 在开始之前,要先提醒各位需要先运行webserver,否则将会遇到一些奇怪的问题喔! 最基本的canvas画布是肯定需要的,Pixi提 ...