Last active
November 28, 2023 07:57
-
-
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!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @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