dsa · easy
Remove Element
Given nums and an integer val, remove every occurrence of val in-place. The relative order of the remaining values may change. Return k, the count of values that are not val. The first k slots of nums must hold those remaining values (any order).
Arguments
nums— mutable array of integersval— value to strip out
The judge only checks the returned k and that the first k entries are a permutation of the kept values.
Example
nums = [3,2,2,3], val = 3 → return 2 and the first two slots are 2,2.
Constraints
0 <= nums.length <= 100 0 <= nums[i], val <= 50 Hidden tests include near-max size for this bound; a slower-than-intended solution TLEs.
Examples
Example 1
Input: [3,2,2,3] 3 Expected: 2
Example 2
Input: [0,1,2,2,3,0,4,2] 2 Expected: 5