Skip to content

Commit 8e62d64

Browse files
committed
refactor remove_duplicates
1 parent 90cdffd commit 8e62d64

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

Sprint-1/Python/remove_duplicates/remove_duplicates.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,16 @@ def remove_duplicates(values: Sequence[ItemType]) -> List[ItemType]:
77
"""
88
Remove duplicate values from a sequence, preserving the order of the first occurrence of each value.
99
10-
Time complexity:
11-
Space complexity:
12-
Optimal time complexity:
10+
Time complexity: O(n)
11+
Space complexity: O(n)
12+
Optimal time complexity: O(n)
1313
"""
1414
unique_items = []
15+
seen = set()
1516

1617
for value in values:
17-
is_duplicate = False
18-
for existing in unique_items:
19-
if value == existing:
20-
is_duplicate = True
21-
break
22-
if not is_duplicate:
18+
if value not in seen:
2319
unique_items.append(value)
20+
seen.add(value)
2421

2522
return unique_items

0 commit comments

Comments
 (0)