Created
May 26, 2021 03:50
-
-
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/
This file contains 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
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