Skip to content

Instantly share code, notes, and snippets.

@dashsaurabh
Created January 20, 2020 11:20
Show Gist options
  • Save dashsaurabh/4d2733819bb435de45a41e83688c05dc to your computer and use it in GitHub Desktop.
Save dashsaurabh/4d2733819bb435de45a41e83688c05dc to your computer and use it in GitHub Desktop.
Remove All Instances from an Element from an Array in Place and Return Length
/**
* @param {number[]} nums
* @param {number} val
* @return {number}
*/
var removeElement = function(nums, val) {
let slow=0;
for(let fast = 0; fast < nums.length; fast++) {
if(nums[fast]!==val) {
nums[slow] = nums[fast];
slow++
}
}
return slow;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment