题解 | #移除数组中的元素#
移除数组中的元素
https://www.nowcoder.com/practice/a93dd26ebb8c425d844acc17bcce9411
快慢指针
function removeWithoutCopy(arr, item) { let fast = 0 let slow = 0 while(fast < arr.length) { if(arr[fast] !== item) { arr[slow] = arr[fast] slow++ } fast++ } arr.length = slow return arr }