From 865cdb88b795894c99cb9dbe7b9f4eb0f1a4e4a0 Mon Sep 17 00:00:00 2001 From: ivan Date: Mon, 22 Sep 2025 04:28:46 -0600 Subject: [PATCH] adding code --- .../remove_duplicates.py | 17 +++++++++++++++++ .../test_remove_duplicates_round_20.py | 11 +++++++++++ 2 files changed, 28 insertions(+) create mode 100644 src/my_project/interviews/top_150_questions_round_20/remove_duplicates.py create mode 100644 tests/test_150_questions_round_20/test_remove_duplicates_round_20.py diff --git a/src/my_project/interviews/top_150_questions_round_20/remove_duplicates.py b/src/my_project/interviews/top_150_questions_round_20/remove_duplicates.py new file mode 100644 index 00000000..a0d00910 --- /dev/null +++ b/src/my_project/interviews/top_150_questions_round_20/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_20/test_remove_duplicates_round_20.py b/tests/test_150_questions_round_20/test_remove_duplicates_round_20.py new file mode 100644 index 00000000..1300f563 --- /dev/null +++ b/tests/test_150_questions_round_20/test_remove_duplicates_round_20.py @@ -0,0 +1,11 @@ +import unittest +from src.my_project.interviews.top_150_questions_round_20\ +.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