Skip to content

Commit 565fdde

Browse files
committed
adding number of 1 bits
1 parent 33f90c2 commit 565fdde

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from typing import List, Union, Collection, Mapping, Optional
2+
from abc import ABC, abstractmethod
3+
4+
class Solution:
5+
def hammingWeight(self, n: int) -> int:
6+
return bin(n).count('1')
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import unittest
2+
from src.my_project.interviews.top_150_questions_round_16\
3+
.number_of_1_bits import Solution
4+
5+
6+
class NumberOfOnesTestCase(unittest.TestCase):
7+
8+
def test_number_of_ones(self):
9+
solution = Solution()
10+
output = solution.hammingWeight(n=11)
11+
target = 3
12+
self.assertEqual(output, target)

0 commit comments

Comments
 (0)