Skip to content

Commit d26609c

Browse files
solves number of one bits in python
1 parent e46e867 commit d26609c

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
| 172 | [Factoring Trailing Zeroes](https://leetcode.com/problems/factorial-trailing-zeroes) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/FactorialTrailingZeros.java) |
5959
| 189 | [Rotate Array](https://leetcode.com/problems/rotate-array) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/RotateArray.java) |
6060
| 190 | [Reverse Bits](https://leetcode.com/problems/reverse-bits) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/ReverseBits.java) |
61-
| 191 | [Number of One Bits](https://leetcode.com/problems/number-of-1-bits) | Easy |
61+
| 191 | [Number of One Bits](https://leetcode.com/problems/number-of-1-bits) | Easy | [![Python](https://img.icons8.com/color/35/000000/python.png)]() |
6262
| 198 | [House Robber](https://leetcode.com/problems/house-robber) | Easy |
6363
| 202 | [Happy Number](https://leetcode.com/problems/happy-number) | Easy |
6464
| 203 | [Remove Linked List Elements](https://leetcode.com/problems/remove-linked-list-elements) | Easy |

python/number_of_1_bits.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
class Solution:
2+
def hammingWeight(self, number: int) -> int:
3+
binary = bin(number)
4+
count = 0
5+
for index in range(2, len(binary)):
6+
if int(binary[index]) == 1:
7+
count += 1
8+
return count
9+

0 commit comments

Comments
 (0)