Skip to main content

191 - Number of 1 Bits

Details

KeyValue
Linkhttps://leetcode.com/problems/number-of-1-bits/
LanguagePython 3
Runtime30 ms, faster than 91.85% of Python3 online submissions for Number of 1 Bits
Memory Usage13.8 MB, less than 95.07% of Python3 online submissions for Number of 1 Bits

Procedure

  1. TBD...

Code

class Solution:
def hammingWeight(self, n: int) -> int:
number_of_ones = 0
while n:
n &= n - 1
number_of_ones += 1
return number_of_ones