Problem
Given a list nums and a value val, remove every occurrence of `val` in place. Return k, the number of elements that are not val. The first `k` slots of nums must hold those elements, in any order; whatever comes after them does not matter.
Example 1
- Input
- nums = [3, 2, 2, 3], val = 3
- Output
- k = 2, first two are [2, 2]
Example 2
- Input
- nums = [0, 1, 2, 2, 3, 0, 4, 2], val = 2
- Output
- k = 5, first five are 0, 1, 3, 0, 4 in some order
Constraints
0 <= nums.length <= 1000 <= nums[i] <= 500 <= val <= 100Use O(1) extra space.