From 707e68cf0abea76304a522cec30283797d2f1a6b Mon Sep 17 00:00:00 2001 From: Kiril Kovachev Date: Fri, 8 Mar 2024 17:14:04 +0000 Subject: [PATCH] Add Remove Element --- python/remove_element.py | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 python/remove_element.py diff --git a/python/remove_element.py b/python/remove_element.py new file mode 100644 index 0000000..f82c8cc --- /dev/null +++ b/python/remove_element.py @@ -0,0 +1,8 @@ +class Solution: + def removeElement(self, nums: List[int], val: int) -> int: + n = len(nums) + for i in range(n-1, -1, -1): + if nums[i] == val: + del nums[i] + n -= 1 + return n