Skip to content

Commit 18ef494

Browse files
committed
Refactor: Use set intersection
1 parent 779628c commit 18ef494

1 file changed

Lines changed: 4 additions & 11 deletions

File tree

Sprint-1/Python/find_common_items/find_common_items.py

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,8 @@ def find_common_items(
99
"""
1010
Find common items between two arrays.
1111
12-
Time Complexity:
13-
Space Complexity:
14-
Optimal time complexity:
12+
Time Complexity: O(n + m) process both sequences
13+
Space Complexity:O(n + m) two sets are created
14+
Optimal time complexity:O(n + m) must check all elements
1515
"""
16-
common_items: List[ItemType] = []
17-
second_sequence_set = set(second_sequence)
18-
19-
for i in first_sequence:
20-
if i in second_sequence_set and i not in common_items:
21-
common_items.append(i)
22-
23-
return common_items
16+
return list(set(first_sequence).intersection(second_sequence))

0 commit comments

Comments
 (0)