Remove Element

Easy

Given an array nums and a value val, return a new array with every occurrence of val removed.

The relative order of the remaining elements must be kept.

Example 1

removeElement()
Input
nums = [3,2,2,3], val = 3
Output
[2,2]

Example 2

removeElement()
Input
nums = [0,1,2,2,3,0,4,2], val = 2
Output
[0,1,3,0,4]
Constraints
0 <= nums.length <= 100
0 <= nums[i], val <= 50

Topics

ArraysTwo Pointers

Implement removeElement in the editor and return the answer — printing it is never graded.