Created
January 20, 2020 11:20
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @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