
Leetcode Problem 26: Remove Duplicates from Sorted Array
Given an integer array nums sorted in non-decreasing order, remove the duplicates in-place such that each unique element appears only once. The relative order of the elements should be kept the same. Return k after placing the final result in the first k slots of nums.
function removeDuplicates(nums: number[]): number {
let leftLimit = 0
for (let current = 1; current < nums.length; current++) {
if (nums[leftLimit] !== nums[current]) {
nums[++leftLimit] = nums[current]
}
}
return leftLimit + 1
};
console.log(removeDuplicates([0,0,1,1,1,2,2,3,3,4]))