Python solution, beats 91%, but any suggestions for improvement?


  • 0
    R

    Hi, does anyone have any ways to improve this?

     def hammingWeight(self, n):
         counter = 0
         for i in range (0,32):
            if (n & 1) == 1:
                 counter += 1
            n >>= 1
         
        return counter

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.