diff --git a/src/my_project/interviews/top_150_questions_round_19/number_of_one_bits.py b/src/my_project/interviews/top_150_questions_round_19/number_of_one_bits.py new file mode 100644 index 00000000..f1cfb550 --- /dev/null +++ b/src/my_project/interviews/top_150_questions_round_19/number_of_one_bits.py @@ -0,0 +1,6 @@ +from typing import List, Union, Collection, Mapping, Optional +from abc import ABC, abstractmethod + +class Solution: + def hammingWeight(self, n: int) -> int: + return bin(n).count('1') \ No newline at end of file diff --git a/tests/test_150_questions_round_19/test_number_of_one_bits_round_19.py b/tests/test_150_questions_round_19/test_number_of_one_bits_round_19.py new file mode 100644 index 00000000..4130ada0 --- /dev/null +++ b/tests/test_150_questions_round_19/test_number_of_one_bits_round_19.py @@ -0,0 +1,11 @@ +import unittest +from src.my_project.interviews.top_150_questions_round_19\ +.number_of_one_bits import Solution + +class NumberOfOnesTestCase(unittest.TestCase): + + def test_number_of_ones(self): + solution = Solution() + output = solution.hammingWeight(n=11) + target = 3 + self.assertEqual(output, target) \ No newline at end of file