由网友(时光路人)分享简介:有效的方式来计数的数量为O二进制重新presentation 1的个数(1)如果你有足够的内存一起玩。这是一个面试问题,我发现在一个网上论坛,但一直无人接听。有人可以提出建议,我不能想办法做到在O(1)的时间?Efficient way to count number of 1s in the binary repr...
有效的方式来计数的数量为O二进制重新presentation 1的个数(1)如果你有足够的内存一起玩。这是一个面试问题,我发现在一个网上论坛,但一直无人接听。有人可以提出建议,我不能想办法做到在O(1)的时间?
Efficient way to count number of 1s in the binary representation of a number in O(1) if you have enough memory to play with. This is an interview question I found on an online forum, but it had no answer. Can somebody suggest something, I cant think of a way to do it in O(1) time?
推荐答案
这就是汉明权重的问题,又名人口数。链接提及高效的实现。引用:
That's the Hamming weight problem, a.k.a. population count. The link mentions efficient implementations. Quoting:
通过无限的记忆,我们可以简单地创建的每个64位整数的汉明权的大型查找表
With unlimited memory, we could simply create a large lookup table of the Hamming weight of every 64 bit integer
相关推荐
最新文章