From ee47582cc5c6a8f774b005d61fded276e48f2dd4 Mon Sep 17 00:00:00 2001 From: ivan Date: Wed, 11 Dec 2024 04:16:38 -0600 Subject: [PATCH] removing element --- .../top_150_questions_round_12/remove_element.py | 10 ++++++++++ .../test_remove_element_round_12.py | 13 +++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 src/my_project/interviews/top_150_questions_round_12/remove_element.py create mode 100644 tests/test_150_questions_round_12/test_remove_element_round_12.py diff --git a/src/my_project/interviews/top_150_questions_round_12/remove_element.py b/src/my_project/interviews/top_150_questions_round_12/remove_element.py new file mode 100644 index 00000000..7117bb88 --- /dev/null +++ b/src/my_project/interviews/top_150_questions_round_12/remove_element.py @@ -0,0 +1,10 @@ +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/tests/test_150_questions_round_12/test_remove_element_round_12.py b/tests/test_150_questions_round_12/test_remove_element_round_12.py new file mode 100644 index 00000000..264e549f --- /dev/null +++ b/tests/test_150_questions_round_12/test_remove_element_round_12.py @@ -0,0 +1,13 @@ +import unittest +from src.my_project.interviews.top_150_questions_round_12\ +.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