Last active
January 19, 2020 09:06
-
-
Save dashsaurabh/4f57576d8418519bb2fa1dfdddad90e5 to your computer and use it in GitHub Desktop.
Remove Duplicates From a Sorted Array in Single Pass
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
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