nums and a number unwanted. Remove every occurrence of unwanted from the array, working directly in nums without a second array.
Say k elements are left afterwards. The first k cells of nums must then hold exactly those elements, in any order; whatever sits in the cells past them does not matter.
Return k.nums=[4, 1, 4, 4, 9], unwanted=4 → 2
Once every 4 is gone, 1 and 9 remain, which is two elements. The first two cells of nums must hold 1 and 9 in any order.
nums=[3, 3], unwanted=3 → 0
Every element equals unwanted, so nothing is left.
nums=[0, 2, 5], unwanted=7 → 3
There is no 7 in the array, so all three elements stay.
nums.length ≤ 100nums[i] ≤ 50unwanted ≤ 100nums=[4, 1, 4, 4, 9], unwanted=4
2
Run checks the first 3 tests in your browser. Submit checks all 111 tests on the server, hidden ones included.