From 5893d727950f0c995912aeefa217041112609d44 Mon Sep 17 00:00:00 2001 From: ivan Date: Thu, 20 Mar 2025 04:36:17 -0600 Subject: [PATCH] addig reverse bits --- .../top_150_questions_round_14/reverse_binary.py | 6 ++++++ .../test_reverse_binary_round_14.py | 11 +++++++++++ 2 files changed, 17 insertions(+) create mode 100644 src/my_project/interviews/top_150_questions_round_14/reverse_binary.py create mode 100644 tests/test_150_questions_round_14/test_reverse_binary_round_14.py diff --git a/src/my_project/interviews/top_150_questions_round_14/reverse_binary.py b/src/my_project/interviews/top_150_questions_round_14/reverse_binary.py new file mode 100644 index 00000000..e79d85e3 --- /dev/null +++ b/src/my_project/interviews/top_150_questions_round_14/reverse_binary.py @@ -0,0 +1,6 @@ +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_14/test_reverse_binary_round_14.py b/tests/test_150_questions_round_14/test_reverse_binary_round_14.py new file mode 100644 index 00000000..5d144456 --- /dev/null +++ b/tests/test_150_questions_round_14/test_reverse_binary_round_14.py @@ -0,0 +1,11 @@ +import unittest +from src.my_project.interviews.top_150_questions_round_14\ +.reverse_binary 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