From 818b1abefb846a94d6b5b9b64536b3d92d456bb3 Mon Sep 17 00:00:00 2001 From: ivan Date: Sun, 19 Oct 2025 03:45:31 -0600 Subject: [PATCH] adding algo --- .../top_150_questions_round_20/single_number.py | 12 ++++++++++++ .../test_single_number_round_20.py | 11 +++++++++++ 2 files changed, 23 insertions(+) create mode 100644 src/my_project/interviews/top_150_questions_round_20/single_number.py create mode 100644 tests/test_150_questions_round_20/test_single_number_round_20.py diff --git a/src/my_project/interviews/top_150_questions_round_20/single_number.py b/src/my_project/interviews/top_150_questions_round_20/single_number.py new file mode 100644 index 00000000..c0bec5e0 --- /dev/null +++ b/src/my_project/interviews/top_150_questions_round_20/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_20/test_single_number_round_20.py b/tests/test_150_questions_round_20/test_single_number_round_20.py new file mode 100644 index 00000000..8b1bebd3 --- /dev/null +++ b/tests/test_150_questions_round_20/test_single_number_round_20.py @@ -0,0 +1,11 @@ +import unittest +from src.my_project.interviews.top_150_questions_round_20\ +.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