Skip to content

Commit 12f0bee

Browse files
committed
create set for faster lookup
1 parent f396f7a commit 12f0bee

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

Sprint-1/Python/find_common_items/find_common_items.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@ def find_common_items(
1414
Optimal time complexity:
1515
"""
1616
common_items: List[ItemType] = []
17+
second_sequence_set = set(second_sequence)
18+
1719
for i in first_sequence:
18-
for j in second_sequence:
19-
if i == j and i not in common_items:
20-
common_items.append(i)
21-
return common_items
20+
if i in second_sequence_set and i not in common_items:
21+
common_items.append(i)
22+
23+
return common_items

0 commit comments

Comments
 (0)