Skip to content

Instantly share code, notes, and snippets.

@particle4dev
Created May 26, 2021 03:50
Show Gist options
  • Select an option

  • Save particle4dev/2bd829cbc5bd81b4d2861da1413ca3a1 to your computer and use it in GitHub Desktop.

Select an option

Save particle4dev/2bd829cbc5bd81b4d2861da1413ca3a1 to your computer and use it in GitHub Desktop.

Revisions

  1. particle4dev revised this gist May 26, 2021. 1 changed file with 0 additions and 1 deletion.
    1 change: 0 additions & 1 deletion leetcode-26.ts
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,3 @@
    // https://leetcode.com/problems/remove-duplicates-from-sorted-array/
    function removeDuplicates(nums: number[]): number {
    const list = {};
    let total = 0;
  2. particle4dev revised this gist May 26, 2021. No changes.
  3. particle4dev revised this gist May 26, 2021. No changes.
  4. particle4dev created this gist May 26, 2021.
    15 changes: 15 additions & 0 deletions leetcode-26.ts
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,15 @@
    // 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;
    };