Remove Element
Change nums in place so that all items not equal to val sit at the front, in their original order. Return n, the number of such items.
Only the first n items of nums are checked; whatever sits after them does not matter.
Example 1
nums [3,2,2,3]
val 3
returns [2,2]
Return 2; the first two items must be [2, 2].
Example 2
nums [0,1,2,2,3,0,4,2]
val 2
returns [0,1,3,0,4]
Return 5; the first five items must be [0, 1, 3, 0, 4].
Constraints
0 <= len(nums) <= 500 <= nums[i], val <= 50
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.