[Written explanation will be added soon]
AFFILIATE LINKS
Great resource I use to learn algorithms.
40% off Tech Interview Pro: http://techinterviewpro.com/terriblewhiteboard
20% off CoderPro: http://coderpro.com/terriblewhiteboard
Here is the full implementation.
/**
* @param {number[]} nums
* @return {number}
*/
let removeDuplicates = function(nums) {
if (!nums.length) {
return 0;
}
let pointer1 = 0;
for (let pointer2 = 1; pointer2 < nums.length; pointer2++) {
if (nums[pointer1] !== nums[pointer2]) {
pointer1++;
nums[pointer1] = nums[pointer2];
}
}
return pointer1 + 1;
};