191. Number of 1 Bits
All prompts are owned by LeetCode. To view the prompt, click the title link above.
First completed : July 03, 2024
Last updated : July 03, 2024
Related Topics : Divide and Conquer, Bit Manipulation
Acceptance Rate : 73.37 %
class Solution:
def hammingWeight(self, n: int) -> int:
counter = 0
while n > 0 :
if n % 2 == 1 :
counter += 1
n //= 2
return counter