From ba7d21d9952ca474d214cdfee09f1d630dd44b24 Mon Sep 17 00:00:00 2001 From: ivan Date: Fri, 1 May 2026 04:50:36 -0600 Subject: [PATCH 1/2] adding algo --- .../ex_03_remove_duplicates_i.py | 18 ++++++++++++++++++ .../ex_03_remove_duplicates_i.ts | 15 +++++++++++++++ .../test_03_remove_duplicates_i_round_22.py | 11 +++++++++++ 3 files changed, 44 insertions(+) create mode 100644 src/my_project/interviews/top_150_questions_round_23/ex_03_remove_duplicates_i.py create mode 100644 src/my_project/interviews_typescript/top_150_questions_round_23/ex_03_remove_duplicates_i.ts create mode 100644 tests/test_150_questions_round_23/test_03_remove_duplicates_i_round_22.py diff --git a/src/my_project/interviews/top_150_questions_round_23/ex_03_remove_duplicates_i.py b/src/my_project/interviews/top_150_questions_round_23/ex_03_remove_duplicates_i.py new file mode 100644 index 00000000..c9563896 --- /dev/null +++ b/src/my_project/interviews/top_150_questions_round_23/ex_03_remove_duplicates_i.py @@ -0,0 +1,18 @@ +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/src/my_project/interviews_typescript/top_150_questions_round_23/ex_03_remove_duplicates_i.ts b/src/my_project/interviews_typescript/top_150_questions_round_23/ex_03_remove_duplicates_i.ts new file mode 100644 index 00000000..839b537e --- /dev/null +++ b/src/my_project/interviews_typescript/top_150_questions_round_23/ex_03_remove_duplicates_i.ts @@ -0,0 +1,15 @@ +function removeDuplicates(nums: number[]): number { + let j = 0; + const lenNums = nums.length; + + for (let i = 0; i < lenNums - 1; i++) { + if (nums[i] !== nums[i + 1]) { + nums[j] = nums[i]; + j++; + } + } + + nums[j] = nums[lenNums - 1]; + + return j + 1; +}; \ No newline at end of file diff --git a/tests/test_150_questions_round_23/test_03_remove_duplicates_i_round_22.py b/tests/test_150_questions_round_23/test_03_remove_duplicates_i_round_22.py new file mode 100644 index 00000000..90ddb7e4 --- /dev/null +++ b/tests/test_150_questions_round_23/test_03_remove_duplicates_i_round_22.py @@ -0,0 +1,11 @@ +import unittest +from src.my_project.interviews.top_150_questions_round_23\ +.ex_03_remove_duplicates_i 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 From a8f00148fcfa1a9e3907609a6e8a86adb56a48eb Mon Sep 17 00:00:00 2001 From: ivan Date: Fri, 1 May 2026 04:54:36 -0600 Subject: [PATCH 2/2] adding algo --- ...ates_i_round_22.py => test_03_remove_duplicates_i_round_23.py} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename tests/test_150_questions_round_23/{test_03_remove_duplicates_i_round_22.py => test_03_remove_duplicates_i_round_23.py} (100%) diff --git a/tests/test_150_questions_round_23/test_03_remove_duplicates_i_round_22.py b/tests/test_150_questions_round_23/test_03_remove_duplicates_i_round_23.py similarity index 100% rename from tests/test_150_questions_round_23/test_03_remove_duplicates_i_round_22.py rename to tests/test_150_questions_round_23/test_03_remove_duplicates_i_round_23.py