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
Next Next commit
names completed
  • Loading branch information
bykristea committed Jan 11, 2020
commit 864494db2dc4acc70482f66de1be42af405c34ac
24 changes: 18 additions & 6 deletions names/names.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import time
from names_bst import BinarySearchTree


start_time = time.time()

Expand All @@ -11,14 +13,24 @@
f.close()

duplicates = []
for name_1 in names_1:
for name_2 in names_2:
if name_1 == name_2:
duplicates.append(name_1)

bst = BinarySearchTree('name')
# adding names from list names_1 to the bst
for name in names_1:
bst.insert(name)
# checking all names in list names_2 to see if it exists in the bst. if the bst contains a duplicated name, appended it to the duplicates[] array.
for name in names_2:
if bst.contains(name):
duplicates.append(name)
# for name_1 in names_1:
# for name_2 in names_2:
# if name_1 == name_2:
# duplicates.append(name_1)

## runtime: 0.12141919136047363 seconds NEW ONE ##
end_time = time.time()
print (f"{len(duplicates)} duplicates:\n\n{', '.join(duplicates)}\n\n")
print (f"runtime: {end_time - start_time} seconds")
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
Expand Down