Skip to content

Instantly share code, notes, and snippets.

@particle4dev
Created May 26, 2021 03:50
Show Gist options
  • Save particle4dev/2bd829cbc5bd81b4d2861da1413ca3a1 to your computer and use it in GitHub Desktop.
Save particle4dev/2bd829cbc5bd81b4d2861da1413ca3a1 to your computer and use it in GitHub Desktop.
Leetcode 26 Remove Duplicates from Sorted Array - https://leetcode.com/problems/remove-duplicates-from-sorted-array/
function removeDuplicates(nums: number[]): number {
const list = {};
let total = 0;
for(let i = 0; i < nums.length; i += 1) {
if(!list[nums[i]]) {
list[nums[i]] = true;
total += 1;
} else {
nums.splice(i, 1);
i -= 1;
}
}
return total;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment