Skip to main content

Leetcode - 26. Remove Duplicates from Sorted Array

· One min read

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

Solution 1

/**
* @param {number[]} nums
* @return {number}
*/
var removeDuplicates = function (nums) {
let uniqueCount = 0;

for (let i = 0; i < nums.length; i++) {
if (nums[i] !== nums[i + 1]) {
uniqueCount++;
nums[uniqueCount] = nums[i + 1];
}
}

return uniqueCount;
};

Runtime: 129 ms

Memory Usage: 44.3 MB