Skip to content

Leetcode - 26. Remove Duplicates from Sorted Array #2

@vitabyfrank

Description

@vitabyfrank

https://leetcode.com/problems/remove-duplicates-from-sorted-array/submissions/901455147/

  • 문제를 제대로 이해하지 못함.
  • O(n) 개념 부족.

Do not allocate extra space for another array. You must do this by modifying the input array in-place with O(1) extra memory.

var removeDuplicates = function(nums) {
    // return [...new Set(nums)];
        for (let i = 0; i < nums.length; i++) {
        if (nums[i] === nums[i + 1]) {
            nums.splice(i, 1);
            i--;
        }
    }
};

Metadata

Metadata

Assignees

No one assigned

    Labels

    wrongdouble check

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions