From 0591d14663eeeed3d38b5b102fea37e16252b3a7 Mon Sep 17 00:00:00 2001 From: ivan Date: Thu, 30 Apr 2026 04:40:35 -0600 Subject: [PATCH] adding updates --- .../ex_02_remove_element.py | 11 +++++++++++ .../top_150_questions_round_1/ex_02_remove_element.ts | 1 - .../ex_02_remove_element.ts | 11 +++++++++++ .../test_02_remove_element_round_23.py | 11 +++++++++++ 4 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 src/my_project/interviews/top_150_questions_round_23/ex_02_remove_element.py create mode 100644 src/my_project/interviews_typescript/top_150_questions_round_23/ex_02_remove_element.ts create mode 100644 tests/test_150_questions_round_23/test_02_remove_element_round_23.py diff --git a/src/my_project/interviews/top_150_questions_round_23/ex_02_remove_element.py b/src/my_project/interviews/top_150_questions_round_23/ex_02_remove_element.py new file mode 100644 index 00000000..8521e400 --- /dev/null +++ b/src/my_project/interviews/top_150_questions_round_23/ex_02_remove_element.py @@ -0,0 +1,11 @@ +from typing import List, Union, Collection, Mapping, Optional +from abc import ABC, abstractmethod + +class Solution: + + def removeElement(self, nums: List[int], val: int) -> int: + + while val in nums: + nums.remove(val) + + return len(nums) \ No newline at end of file diff --git a/src/my_project/interviews_typescript/top_150_questions_round_1/ex_02_remove_element.ts b/src/my_project/interviews_typescript/top_150_questions_round_1/ex_02_remove_element.ts index 0b570ca9..a63de82f 100644 --- a/src/my_project/interviews_typescript/top_150_questions_round_1/ex_02_remove_element.ts +++ b/src/my_project/interviews_typescript/top_150_questions_round_1/ex_02_remove_element.ts @@ -8,4 +8,3 @@ function removeElement(nums: number[], val: number): number { }; -console.log(removeElement([3,2,2,3], 3)) \ No newline at end of file diff --git a/src/my_project/interviews_typescript/top_150_questions_round_23/ex_02_remove_element.ts b/src/my_project/interviews_typescript/top_150_questions_round_23/ex_02_remove_element.ts new file mode 100644 index 00000000..0b570ca9 --- /dev/null +++ b/src/my_project/interviews_typescript/top_150_questions_round_23/ex_02_remove_element.ts @@ -0,0 +1,11 @@ +function removeElement(nums: number[], val: number): number { + while (nums.includes(val)){ + const index = nums.indexOf(val); + nums.splice(index, 1); + } + + return nums.length; + +}; + +console.log(removeElement([3,2,2,3], 3)) \ No newline at end of file diff --git a/tests/test_150_questions_round_23/test_02_remove_element_round_23.py b/tests/test_150_questions_round_23/test_02_remove_element_round_23.py new file mode 100644 index 00000000..e8036528 --- /dev/null +++ b/tests/test_150_questions_round_23/test_02_remove_element_round_23.py @@ -0,0 +1,11 @@ +import unittest +from src.my_project.interviews.top_150_questions_round_23\ +.ex_02_remove_element import Solution + +class RemoveElementTestCase(unittest.TestCase): + + def test_remove_element(self): + solution = Solution() + output = solution.removeElement(nums=[3,2,2,3], val=3) + target = 2 + self.assertEqual(output, target) \ No newline at end of file