Cover image for Classic 150 Interview Questions P191 Number of 1 Bits

Classic 150 Interview Questions P191 Number of 1 Bits


Timeline

Timeline

2025-11-25

init

__builtin_popcount

Problem:

You can directly use built-in functions.__builtin_popcount

1234567
class Solution {    public:	int hammingWeight(int n)	{		return __builtin_popcount(n);	}};
Loading comments…