(n)
return 1 + count_ones_recur(n & (n-1))
Using Brian Kernighan's Algorithm. (Recursive Approach)
Using Brian Kernighan's Algorithm. (Recursive Approach)
Using Brian Kernighan s Algorithm . ( Recursive Approach )
def count_ones_recur(n):
    """Using Brian Kernighan's Algorithm. (Recursive Approach)"""

    if not n:
        return 0
    return 1 + count_ones_recur(n & (n-1))
def count_ones_recur ( n ) : if not n : return 0 return 1 + count_ones_recur ( n & ( n - 1 ) )