leetcode刷题,求hamming weight

最近看到一个不错的刷题网站leetCode,于是就去刷题啦,提高一下水平。题目真的是,很有代表性啊,我喜欢!

写一个函数,求出一个无符号整数里面位为1的个数(也就是Hamming Weight算法),例如32位整数11,用二进制表示为00000000000000000000000000001011,因此函数返回值为3

原文如下

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.

(更多…)

你可能还喜欢下面这些文章

使用php curl 的并发能力可以做什么

在php中,没有多线程让编程变得简单。但在一些需要并发提升性能的场景下,显得有些无能为力,比如发起一些http请求。但好在curl扩展可以让我们“并发”去请求网络资源。利用这个特点,我们能做很多有趣的事情。最基础的,并发请求网络资源,提升处理速度。并发访问代码<?phpclass ConcurrencyHTTP { private $_requests; private $_callbacks; private $_currentIndex = 0; public function get($url, $header = array(), $timeout = 3