From 5770496a03682c6739d6fcb82473ec16f78e4da6 Mon Sep 17 00:00:00 2001 From: ivan Date: Sat, 9 Aug 2025 04:24:53 -0600 Subject: [PATCH] adding updates --- .../top_150_questions_round_18/single_number.py | 12 ++++++++++++ .../test_single_number_round_18.py | 11 +++++++++++ 2 files changed, 23 insertions(+) create mode 100644 src/my_project/interviews/top_150_questions_round_18/single_number.py create mode 100644 tests/test_150_questions_round_18/test_single_number_round_18.py diff --git a/src/my_project/interviews/top_150_questions_round_18/single_number.py b/src/my_project/interviews/top_150_questions_round_18/single_number.py new file mode 100644 index 00000000..862cc9d7 --- /dev/null +++ b/src/my_project/interviews/top_150_questions_round_18/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_18/test_single_number_round_18.py b/tests/test_150_questions_round_18/test_single_number_round_18.py new file mode 100644 index 00000000..3ce81636 --- /dev/null +++ b/tests/test_150_questions_round_18/test_single_number_round_18.py @@ -0,0 +1,11 @@ +import unittest +from src.my_project.interviews.top_150_questions_round_18\ +.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)