-
-
Save spreered/740405b172949cd538784aa45b31e9af to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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