26. Remove Duplicates from Sorted Array

202410011626
tags: #array #two-pointers

var removeDuplicates = function(nums) {
	let len = 0;
	for (let i = 0; i < nums.length; i++) {
		if (i === nums.length - 1 || nums[i] !== nums[i + 1]) {
			nums[len] = nums[i];
			len += 1;
		}
	}
	return len;
};

Reference

https://leetcode.com/problems/remove-duplicates-from-sorted-array/