Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit c1de187

Browse files
add solution in Python for 0191_number_of_1_bits.py
1 parent c71fdce commit c1de187

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
def hammingWeight(self, bits: int) -> int:
2+
counter = 0
3+
while (bits):
4+
bits &= (bits - 1)
5+
counter += 1
6+
return counter

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /