-
-
Save ihower/b7e8c3f658b49bd9e261876202810094 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
arr1 = [1,2,3] # [] | |
arr2 = [1,1,2] # [1] | |
arr3 = [1,1,2,2] # [1,2] | |
def find_dup_v1(arr) | |
unique_arr = [] | |
dup_arr = [] | |
arr.each do |a| # O(N) | |
if unique_arr.include?(a) # O(N) | |
dup_arr << a | |
else | |
unique_arr << a | |
end | |
end | |
return dup_arr | |
end | |
puts find_dup_v1(arr1).to_s | |
puts find_dup_v1(arr2).to_s | |
puts find_dup_v1(arr3).to_s |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment