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_23.py b/tests/test_150_questions_round_23/test_03_remove_duplicates_i_round_23.py new file mode 100644 index 00000000..90ddb7e4 --- /dev/null +++ b/tests/test_150_questions_round_23/test_03_remove_duplicates_i_round_23.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