From 55d30b5b4f07c25afcfb33a0e10ba7a00e8cb1c2 Mon Sep 17 00:00:00 2001 From: ivan Date: Sun, 1 Dec 2024 04:29:04 -0600 Subject: [PATCH] adding add binary algo --- .../top_150_questions_round_11/add_binary.py | 6 ++++++ .../test_add_binary_round_11.py | 12 ++++++++++++ 2 files changed, 18 insertions(+) create mode 100644 src/my_project/interviews/top_150_questions_round_11/add_binary.py create mode 100644 tests/test_150_questions_round_11/test_add_binary_round_11.py diff --git a/src/my_project/interviews/top_150_questions_round_11/add_binary.py b/src/my_project/interviews/top_150_questions_round_11/add_binary.py new file mode 100644 index 00000000..31e59a78 --- /dev/null +++ b/src/my_project/interviews/top_150_questions_round_11/add_binary.py @@ -0,0 +1,6 @@ +from typing import List, Union, Collection, Mapping, Optional +from abc import ABC, abstractmethod + +class Solution: + def addBinary(self, a: str, b: str) -> str: + return bin(int(a,2) + int(b,2))[2:] \ No newline at end of file diff --git a/tests/test_150_questions_round_11/test_add_binary_round_11.py b/tests/test_150_questions_round_11/test_add_binary_round_11.py new file mode 100644 index 00000000..0e07e333 --- /dev/null +++ b/tests/test_150_questions_round_11/test_add_binary_round_11.py @@ -0,0 +1,12 @@ +import unittest +from src.my_project.interviews.top_150_questions_round_11\ +.add_binary import Solution + + +class AddBinaryTestCase(unittest.TestCase): + + def test_add_binary(self): + solution = Solution() + output = solution.addBinary(a="11", b="1") + target = "100" + self.assertEqual(output, target) \ No newline at end of file