From 8c39acb2985cdc6a179ecffe64024b6bbd875c02 Mon Sep 17 00:00:00 2001 From: ivan Date: Sat, 31 May 2025 04:35:09 -0600 Subject: [PATCH] adding single number --- .../top_150_questions_round_16/single_number.py | 12 ++++++++++++ .../test_single_number_round_16.py | 11 +++++++++++ 2 files changed, 23 insertions(+) create mode 100644 src/my_project/interviews/top_150_questions_round_16/single_number.py create mode 100644 tests/test_150_questions_round_16/test_single_number_round_16.py diff --git a/src/my_project/interviews/top_150_questions_round_16/single_number.py b/src/my_project/interviews/top_150_questions_round_16/single_number.py new file mode 100644 index 00000000..793f68a0 --- /dev/null +++ b/src/my_project/interviews/top_150_questions_round_16/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 diff --git a/tests/test_150_questions_round_16/test_single_number_round_16.py b/tests/test_150_questions_round_16/test_single_number_round_16.py new file mode 100644 index 00000000..1de9c8e9 --- /dev/null +++ b/tests/test_150_questions_round_16/test_single_number_round_16.py @@ -0,0 +1,11 @@ +import unittest +from src.my_project.interviews.top_150_questions_round_16\ +.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