Problem statement

https://leetcode.com/problems/remove-element/

Solution

Very similar to previous problem, again Two Pointers.

Complexity

Time complexity is $O(n)$, space is $O(1)$.

Code

class Solution:
    def removeElement(self, nums, val):
        slow, fast = 0, 0
        while fast < len(nums):
            if nums[fast] != val:
                nums[slow] = nums[fast]
                slow += 1
            fast += 1
        return slow