Skip to content

Commit

Permalink
Create remove-element.py
Browse files Browse the repository at this point in the history
removes list elements in place. not the most efficient but logically simple
  • Loading branch information
gabedonnan authored Jan 19, 2023
1 parent 32ac792 commit f358f9f
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions remove-element.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class Solution:
def removeElement(self, nums: List[int], val: int) -> int:
indices = []
for i in range(len(nums)):
if nums[i] == val:
indices.append(i)
for j,index in enumerate(indices):
nums.pop(index - j)
return len(nums)

0 comments on commit f358f9f

Please sign in to comment.