From fc9780515362f19ff5575a4ea98408ecab0a1580 Mon Sep 17 00:00:00 2001 From: ivan Date: Sat, 2 May 2026 05:08:37 -0600 Subject: [PATCH] adding updtes --- .../ex_04_remove_duplicates_ii.py | 26 +++++++++++++++++++ .../ex_04_remove_duplicates_ii.ts | 18 +++++++++++++ .../test_04_remove_duplicates_ii_round_23.py | 10 +++++++ 3 files changed, 54 insertions(+) create mode 100644 src/my_project/interviews/top_150_questions_round_23/ex_04_remove_duplicates_ii.py create mode 100644 src/my_project/interviews_typescript/top_150_questions_round_23/ex_04_remove_duplicates_ii.ts create mode 100644 tests/test_150_questions_round_23/test_04_remove_duplicates_ii_round_23.py diff --git a/src/my_project/interviews/top_150_questions_round_23/ex_04_remove_duplicates_ii.py b/src/my_project/interviews/top_150_questions_round_23/ex_04_remove_duplicates_ii.py new file mode 100644 index 00000000..cb7d76f2 --- /dev/null +++ b/src/my_project/interviews/top_150_questions_round_23/ex_04_remove_duplicates_ii.py @@ -0,0 +1,26 @@ +from typing import List, Union, Collection, Mapping, Optional +from abc import ABC, abstractmethod + +class Solution(object): + def removeDuplicates(self, nums): + """ + :type nums: List[int] + :rtype: int + """ + + n = len(nums) + + if n < 3: + return n + + i , j = 1, 2 + + while j < n: + if nums[i-1] != nums[j]: + i += 1 + + + nums[i] = nums[j] + j+= 1 + + return i+1 \ No newline at end of file diff --git a/src/my_project/interviews_typescript/top_150_questions_round_23/ex_04_remove_duplicates_ii.ts b/src/my_project/interviews_typescript/top_150_questions_round_23/ex_04_remove_duplicates_ii.ts new file mode 100644 index 00000000..37941f8e --- /dev/null +++ b/src/my_project/interviews_typescript/top_150_questions_round_23/ex_04_remove_duplicates_ii.ts @@ -0,0 +1,18 @@ +function removeDuplicates(nums: number[]): number { + const n = nums.length; + + if (n < 3) return n; + + let i = 1, j = 2; + + while (j < n) { + if (nums[i - 1] !== nums[j]) { + i++; + } + + nums[i] = nums[j]; + j++; + } + + return i + 1; +}; \ No newline at end of file diff --git a/tests/test_150_questions_round_23/test_04_remove_duplicates_ii_round_23.py b/tests/test_150_questions_round_23/test_04_remove_duplicates_ii_round_23.py new file mode 100644 index 00000000..ad329a2c --- /dev/null +++ b/tests/test_150_questions_round_23/test_04_remove_duplicates_ii_round_23.py @@ -0,0 +1,10 @@ +import unittest +from src.my_project.interviews.top_150_questions_round_23\ +.ex_04_remove_duplicates_ii import Solution + +class RemoveDuplicatesTestCaseII(unittest.TestCase): + def test_remove_duplicates(self): + solution = Solution() + output = solution.removeDuplicates(nums = [1,1,1,2,2,3]) + target = 5 + self.assertEqual(output, target) \ No newline at end of file