Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
attempted stretch goal. got runtime down to 0.004s from 0.006s
  • Loading branch information
clifhodges13 committed Jun 27, 2020
commit 186daa943d0f1f97f6d7dcff4c70ecb69def93d1
24 changes: 15 additions & 9 deletions names/names.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,25 @@
# Append the items that exist in both lists to the duplicates list

# initialize BST with a placeholder node
bst = BSTNode('placeholder')
for name in names_1:
bst.insert(name)
# bst = BSTNode('placeholder')
# for name in names_1:
# bst.insert(name)

for name in names_2:
if bst.contains(name):
duplicates.append(name)
# for name in names_2:
# if bst.contains(name):
# duplicates.append(name)

end_time = time.time()
print (f"{len(duplicates)} duplicates:\n\n{', '.join(duplicates)}\n\n")
print (f"runtime: {end_time - start_time} seconds")
# end_time = time.time()
# print (f"{len(duplicates)} duplicates:\n\n{', '.join(duplicates)}\n\n")
# print (f"runtime: {end_time - start_time} seconds")

# ---------- Stretch Goal -----------
# Python has built-in tools that allow for a very efficient approach to this problem
# What's the best time you can accomplish? Thare are no restrictions on techniques or data
# structures, but you may not import any additional libraries that you did not write yourself.

duplicates = set(names_1).intersection(names_2)

end_time = time.time()
print (f"{len(duplicates)} duplicates:\n\n{', '.join(duplicates)}\n\n")
print (f"runtime: {end_time - start_time} seconds")