Description
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.
Examples
Input:
nums = [3,2,2,3], val = 3Output:
2Explanation:
Your function should return k = 2, with the first two elements being 2.
Input:
nums = [0,1,2,2,3,0,4,2], val = 2Output:
5Explanation:
Your function should return k = 5.
Input:
nums = [1], val = 1Output:
0Explanation:
The only element equals val, so all elements are removed, leaving length 0.
Constraints
- •
0 ≤ nums.length ≤ 100 - •
0 ≤ nums[i] ≤ 50 - •
0 ≤ val ≤ 100