Created
July 19, 2021 16:22
-
-
Save SiegeSailor/b5a6166b6e270309186de1059a981a29 to your computer and use it in GitHub Desktop.
Remove Duplicates from Sorted Array.
This file contains hidden or 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
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