(n)
return count
Using Brian Kernighan's Algorithm. (Iterative Approach)
Using Brian Kernighan's Algorithm. (Iterative Approach)
Using Brian Kernighan s Algorithm . ( Iterative Approach )
def count_ones_iter(n):
    """Using Brian Kernighan's Algorithm. (Iterative Approach)"""

    count = 0
    while n:
        n &= (n-1)
        count += 1
    return count
def count_ones_iter ( n ) : count = 0 while n : n &= ( n - 1 ) count += 1 return count