Remove Element
Given an integer array nums and an integer val, remove all occurrences of val in-place. The order of the elements may be changed. Then return the number of elements in nums which are not equal to val.
Remove Element
Given an integer array nums and an integer val, remove all occurrences of val in-place. The order of the elements may be changed. Then return the number of elements in nums which are not equal to val.
Example 1
Input: nums = [3,2,2,3], val = 3 Output: 2
Example 2
Input: nums = [0,1,2,2,3,0,4,2], val = 2 Output: 5
Show hint
Use two pointers: one to iterate, another to track position for non-val elements. Copy non-val elements forward.
Sign in to submit, save progress and mark problems as solved. You can still run your code.
Loading editor...
nums =
[3,2,2,3]
val =
3
Expected
2