Skip to content

Commit 5317406

Browse files
authored
Merge pull request #1216 from ivan1016017/march21
adding number of one bits
2 parents 223e57b + 5a9bf5c commit 5317406

2 files changed

Lines changed: 19 additions & 0 deletions

File tree

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: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import unittest
2+
from src.my_project.interviews.top_150_questions_round_14\
3+
.numer_of_one_bits import Solution
4+
5+
class NumberOfOnesTestCase(unittest.TestCase):
6+
7+
def test_number_of_ones(self):
8+
solution = Solution()
9+
output = solution.hammingWeight(n=11)
10+
target = 3
11+
self.assertEqual(output, target)
12+
13+

0 commit comments

Comments
 (0)