loading...

LeetCode in Ruby: 26. Remove Duplicates from Sorted Array

algobot76 profile image Kaitian Xie Updated on ・1 min read
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)

Discussion

pic
Editor guide
Collapse
olimpioadolfo profile image
Olimpio

Interesting... And it's fast...