Write a function that takes an unsigned integer and returns the number of ‘1’ bits it has (also known as the Hamming weight).
Note:
1 | Note that in some languages such as Java, there is no unsigned integer type. In this case, the input will be given as a signed integer type. It should not affect your implementation, as the integer's internal binary representation is the same, whether it is signed or unsigned. |
轉二進count 1
1 | # T:O(n), S:O(1) |
如果你覺得這篇文章很棒,請你不吝點讚 (゚∀゚)