From e7504e46214b8b1e9384ae2db87a98a18440a8bb Mon Sep 17 00:00:00 2001 From: ivan Date: Wed, 4 Dec 2024 04:42:02 -0600 Subject: [PATCH] adding single number algo --- .../top_150_questions_round_11/single_number.py | 12 ++++++++++++ .../test_single_number_round_11.py | 11 +++++++++++ 2 files changed, 23 insertions(+) create mode 100644 src/my_project/interviews/top_150_questions_round_11/single_number.py create mode 100644 tests/test_150_questions_round_11/test_single_number_round_11.py diff --git a/src/my_project/interviews/top_150_questions_round_11/single_number.py b/src/my_project/interviews/top_150_questions_round_11/single_number.py new file mode 100644 index 00000000..c0bec5e0 --- /dev/null +++ b/src/my_project/interviews/top_150_questions_round_11/single_number.py @@ -0,0 +1,12 @@ +from typing import List, Union, Collection, Mapping, Optional +from abc import ABC, abstractmethod + +class Solution: + def singleNumber(self, nums: List[int]) -> int: + + answer = 0 + + for num in nums: + answer ^= num + + return answer \ No newline at end of file diff --git a/tests/test_150_questions_round_11/test_single_number_round_11.py b/tests/test_150_questions_round_11/test_single_number_round_11.py new file mode 100644 index 00000000..02547ea5 --- /dev/null +++ b/tests/test_150_questions_round_11/test_single_number_round_11.py @@ -0,0 +1,11 @@ +import unittest +from src.my_project.interviews.top_150_questions_round_11\ +.single_number import Solution + +class SingleNumberTestCase(unittest.TestCase): + + def test_single_number(self): + solution = Solution() + output = solution.singleNumber(nums=[2,2,1]) + target = 1 + self.assertEqual(output, target) \ No newline at end of file