CodeChallenge icon indicating copy to clipboard operation
CodeChallenge copied to clipboard

Alternative approach

Open namwanza opened this issue 5 years ago • 0 comments

I saw your solution when I was looking for an efficient way to do this operation - but later came up with an alternative approach: This is much faster.

var countBits = function(n) { var count = 0; while (n != 0) { n = n & (n-1); count++; } return count;; }

I thought I would share since it might be useful to you.

namwanza avatar Mar 26 '20 21:03 namwanza