Skip to content

Alternative approach  #3

Description

@namwanza

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions