Skip to content

Instantly share code, notes, and snippets.

@kelvingraddick
Last active November 28, 2023 07:57
Show Gist options
  • Save kelvingraddick/75bf976d0356e609e540245a1122e1f2 to your computer and use it in GitHub Desktop.
Save kelvingraddick/75bf976d0356e609e540245a1122e1f2 to your computer and use it in GitHub Desktop.
Here is the problem and solution to a coding challenge from Leetcode.com called Remove Duplicates from Sorted Array!
/**
* @param {number[]} nums
* @return {number}
*/
const removeDuplicates = function(nums) {
let insertPointer = 1;
for (let i = 1; i < nums.length; i++) {
if (nums[i] !== nums[i - 1]) {
nums[insertPointer] = nums[i];
insertPointer++;
}
}
return insertPointer;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment