Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """
- A1: Slow and fast pointer approach: The overall idea is to copy the non-target values from the array to the first few elements. For that, maintain a fast and slow pointer and iterate over slow pointer only if you encounter the non-target value. Once that is seen, what you do is overwrite the elements to the first part of the array
- """
- class Solution:
- def removeElement(self, nums: List[int], val: int) -> int:
- count = 0
- for i in range(len(nums)):
- if nums[i]!=val:
- nums[count] = nums[i]
- count = count + 1
- return count
Advertisement
Add Comment
Please, Sign In to add comment