Your browser does not seem to support JavaScript. As a result, your viewing experience will be diminished, and you have been placed in read-only mode.

Please download a browser that supports JavaScript, or enable it if it's disabled (i.e. NoScript).

int hammingWeight(uint32_t n) { int res =0; while (n!=0) { n = n & (n-1); res++; } return res; }

The number of iterations depends on the number of '1' in n's binary representation. I don't see why this is O(log n).

Hey, sure! That should be number of '1's of course.

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.