Skip to content

Instantly share code, notes, and snippets.

@spreered

spreered/remove_duplicates1.rb Secret

Created Sep 13, 2017
Embed
What would you like to do?
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