Skip to content

Instantly share code, notes, and snippets.

@SiegeSailor
Created July 19, 2021 16:22
Show Gist options
  • Save SiegeSailor/b5a6166b6e270309186de1059a981a29 to your computer and use it in GitHub Desktop.
Save SiegeSailor/b5a6166b6e270309186de1059a981a29 to your computer and use it in GitHub Desktop.
Remove Duplicates from Sorted Array.
function removeDuplicates(nums: number[]): number {
if (nums.length == 0) return 0;
let current = 0;
for (let index = 0; index <= nums.length - 1; index++){
if (nums[current] !== nums[index]){
current++;
nums[current] = nums[index]
}
}
return current + 1;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment