Skip to content

Instantly share code, notes, and snippets.

@dashsaurabh
Last active January 19, 2020 09:06
Show Gist options
  • Save dashsaurabh/4f57576d8418519bb2fa1dfdddad90e5 to your computer and use it in GitHub Desktop.
Save dashsaurabh/4f57576d8418519bb2fa1dfdddad90e5 to your computer and use it in GitHub Desktop.
Remove Duplicates From a Sorted Array in Single Pass
var removeDuplicates = function(nums) {
if(nums.length === 0) return 0;
let slow = 0;
for(let fast = 0; fast < nums.length; fast++) {
if(nums[slow] !== nums[fast]){
slow++;
nums[slow] = nums[fast]
}
}
return slow + 1;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment