There are three solutions to calculate hamming weight.
bruce force
1 | int hammingWeight(uint32_t n) { |
lowbit
operator AND between n with n-1 will remove the right 1.
1 | int hammingWeight(uint32_t n) |
tree pattern
1 | int hammingWeight(uint32_t n) |
赏
使用支付宝打赏
使用微信打赏
若你觉得我的文章对你有帮助,欢迎点击上方按钮对我打赏
扫描二维码,分享此文章