Given an integer array nums and an integer val, remove all occurrences of val in nums in-place. The order of the elements may be changed. Then return the number of elements in nums which are not equal to val. Consider the number of elements in nums which are not equal to val be k, to get accepted, you need to change the array nums such that the first k elements of nums contain the elements which are not equal to val.
Example 1
Input: nums = [3,2,2,3], val = 3
Output: [2,2]
Explanation: Removing both 3s leaves the two 2s, so k = 2.
Example 2
Input: nums = [0,1,2,2,3,0,4,2], val = 2
Output: [0,1,3,0,4]
Explanation: Removing the three 2s leaves [0,1,3,0,4], so k = 5.
Example 3
Input: nums = [1], val = 1
Output: []
Explanation: The only element equals val, so nothing is left.
Keep a slow write-pointer for the next kept slot. Scan with a fast pointer; whenever the current value is not the one to remove, copy it to the slow slot and advance. The slow pointer ends as the count of kept elements.
Run checks all cases above. Submit evaluates all test cases.