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

public class Solution {
public int HammingWeight(uint n) {
int count;
for (count=0; n > 0 ; count++){
n &= n-1;
}
return count;
}
}

• 本文已收录于以下专栏：

【LeetCode】Number of 1 Bits 解题报告

Number of 1 Bits[LeetCode]https://leetcode.com/problems/number-of-1-bits/Total Accepted: 88721 Total...

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

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

LeetCode题解：number-of-1-bits

• yums467
• 2015年03月26日 15:07
• 358

LeetCode-Number of 1 Bits

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

[LeetCode]Number of 1 Bits

QuestionWrite a function that takes an unsigned integer and returns the number of ’1’ bits it has (a...
• byamao1
• 2016年12月13日 22:19
• 83

举报原因： 您举报文章：LeetCode -- Number of 1 Bits 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)