题目链接
https://leetcode.com/problems/number-of-1-bits/
题目原文
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‘ (该结果也被称为“Hamming weight”)。
比如,32位整数 ‘11’ 的二进制表示为 00000000000000000000000000001011 ,所以函数应该返回3。
思路方法
思路一
按照定义,将输入的数表示成二进制的字符串,数一下有多少个1即可。
代码
class Solution
4121




被折叠的 条评论
为什么被折叠?



