def remove_duplicates(nums)
nums.uniq!
return nums.length
end
First, use uniq!
to remove all the duplicates in nums
. Then return its length.
Time complexity: O(n)
Extra memory: O(1)
def remove_duplicates(nums)
nums.uniq!
return nums.length
end
First, use uniq!
to remove all the duplicates in nums
. Then return its length.
Time complexity: O(n)
Extra memory: O(1)
For further actions, you may consider blocking this person and/or reporting abuse
Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.
Mike Young -
Mike Young -
Mike Young -
Mike Young -
Top comments (1)
Interesting... And it's fast...