From ab25aecc737af09eb6beb1efd5712c6e23464176 Mon Sep 17 00:00:00 2001 From: ivan Date: Mon, 27 Oct 2025 04:21:50 -0600 Subject: [PATCH] adding algo --- .../remove_duplicates.py | 17 +++++++++++++++++ .../test_remove_duplicates_round_21.py | 11 +++++++++++ 2 files changed, 28 insertions(+) create mode 100644 src/my_project/interviews/top_150_questions_round_21/remove_duplicates.py create mode 100644 tests/test_150_questions_round_21/test_remove_duplicates_round_21.py diff --git a/src/my_project/interviews/top_150_questions_round_21/remove_duplicates.py b/src/my_project/interviews/top_150_questions_round_21/remove_duplicates.py new file mode 100644 index 00000000..a0d00910 --- /dev/null +++ b/src/my_project/interviews/top_150_questions_round_21/remove_duplicates.py @@ -0,0 +1,17 @@ +from typing import List, Union, Collection, Mapping, Optional +from abc import ABC, abstractmethod + +class Solution: + def removeDuplicates(self, nums: List[int]) -> int: + + j = 0 + len_nums = len(nums) + + for i in range(len_nums - 1): + if nums[i] != nums[i+1]: + nums[j] = nums[i] + j += 1 + + nums[j] = nums[len_nums - 1] + + return j + 1 \ No newline at end of file diff --git a/tests/test_150_questions_round_21/test_remove_duplicates_round_21.py b/tests/test_150_questions_round_21/test_remove_duplicates_round_21.py new file mode 100644 index 00000000..1c05d9a2 --- /dev/null +++ b/tests/test_150_questions_round_21/test_remove_duplicates_round_21.py @@ -0,0 +1,11 @@ +import unittest +from src.my_project.interviews.top_150_questions_round_21\ +.remove_duplicates import Solution + +class RemoveDuplicatesTestCase(unittest.TestCase): + + def test_remove_duplicates(self): + solution = Solution() + output = solution.removeDuplicates(nums=[1,1,2]) + target = 2 + self.assertEqual(output, target) \ No newline at end of file