diff --git a/src/my_project/interviews/top_150_questions_round_12/revert_bits.py b/src/my_project/interviews/top_150_questions_round_12/revert_bits.py new file mode 100644 index 00000000..b866cda1 --- /dev/null +++ b/src/my_project/interviews/top_150_questions_round_12/revert_bits.py @@ -0,0 +1,7 @@ +from typing import List, Union, Collection, Mapping, Optional +from abc import ABC, abstractmethod + +class Solution: + def reverseBits(self, n: int) -> int: + return int((('{0:032b}'.format(n))[::-1]),2) + \ No newline at end of file diff --git a/tests/test_150_questions_round_12/test_revert_bits_round_12.py b/tests/test_150_questions_round_12/test_revert_bits_round_12.py new file mode 100644 index 00000000..d0defc8a --- /dev/null +++ b/tests/test_150_questions_round_12/test_revert_bits_round_12.py @@ -0,0 +1,11 @@ +import unittest +from src.my_project.interviews.top_150_questions_round_12\ +.revert_bits import Solution + +class ReverseBitsTestCase(unittest.TestCase): + + def test_reverse_bits(self): + solution = Solution() + output = solution.reverseBits(2) + target = 1073741824 + self.assertEqual(output, target) \ No newline at end of file