DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

Kaitian Xie
Kaitian Xie

Posted on • Updated on

LeetCode in Ruby: 26. Remove Duplicates from Sorted Array

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)

Top comments (1)

Collapse
 
rnrnshn profile image
Olimpio

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

All DEV content is created by the community!

Hey, if you're landing here for the first time, you should know that this website is a global community of folks who blog about their experiences to help folks like you out.

Sign up now if you're curious. It's free!