191. Number of 1 Bits
文章目录
Problem
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.
Remark
这个题总归还是很简单的。
|
|
n &= n - 1
就会使二进制n,1的个数少一个,很神奇。
|
|