Last active
January 20, 2016 02:45
-
-
Save abrahamsangha/09664d58a5527152fa10 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# O(n^2) | |
def dedupe(sorted_array) | |
previous_values = [] | |
sorted_array.map do |element| | |
if previous_values.include? element | |
next | |
else | |
previous_values << element | |
element | |
end | |
end.compact | |
end | |
# O(n) | |
def dedupe(sorted_array) | |
previous_values = [] | |
sorted_array.map do |element| | |
if element == previous_values.last | |
next | |
else | |
previous_values << element | |
element | |
end | |
end.compact | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment