DEV Community

Kaitian Xie
Kaitian Xie

Posted on • Edited on

2 2

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...

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay