Skip to content

Instantly share code, notes, and snippets.

@spreered
Created September 13, 2017 08:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save spreered/740405b172949cd538784aa45b31e9af to your computer and use it in GitHub Desktop.
Save spreered/740405b172949cd538784aa45b31e9af to your computer and use it in GitHub Desktop.
def remove_duplicates(nums)
i=0
len= nums.length
for n in (1..len)
if (nums[i] == nums[i+1])
nums.delete_at(i)
else
i=i+1
end
end
return nums.length
end
def remove_duplicates(nums)
left = 0
right = 1
while (right < nums.length) do
nums[left] == nums[right] ? (nums[right] = nil) : (left = right)
right += 1
end
nums.compact!
nums.length
end
def remove_duplicates(nums)
nums.uniq!
nums.length
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment