Fundamentals/Remove Element
← PrevNext →
Given an array nums and a value target, return a new array containing the elements of nums in their original order with every occurrence of target removed.
Input
nums: an array of integers
target: the integer value to remove
Output
A new array of the elements of nums that are not equal to target, in original order.
Examples
Example 1
Inputnums = [1, 2, 3, 2, 4, 2], target = 2
Output[1, 3, 4]
Example 2
Inputnums = [1, 2, 3], target = 7
Output[1, 2, 3]
Constraints
0 <= nums.length
Solve in O(n) time.