Remove Duplicates from Sorted Array
- javascript
- arrays
Problem URL:Remove Duplicates from Sorted Array
My Solution
JavaScript
/**
* @param {number[]} nums
* @return {number}
*/
const removeDuplicates = (nums) => {
let i = 0;
while (i < nums.length) {
if (nums.indexOf(nums[i]) !== i) {
nums.splice(i, 1);
} else {
i += 1;
}
}
return nums.length;
};
Let's Connect
Twitter •GitHub •LinkedIn