We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 90cdffd commit 8e62d64Copy full SHA for 8e62d64
Sprint-1/Python/remove_duplicates/remove_duplicates.py
@@ -7,19 +7,16 @@ def remove_duplicates(values: Sequence[ItemType]) -> List[ItemType]:
7
"""
8
Remove duplicate values from a sequence, preserving the order of the first occurrence of each value.
9
10
- Time complexity:
11
- Space complexity:
12
- Optimal time complexity:
+ Time complexity: O(n)
+ Space complexity: O(n)
+ Optimal time complexity: O(n)
13
14
unique_items = []
15
+ seen = set()
16
17
for value in values:
- is_duplicate = False
18
- for existing in unique_items:
19
- if value == existing:
20
- is_duplicate = True
21
- break
22
- if not is_duplicate:
+ if value not in seen:
23
unique_items.append(value)
+ seen.add(value)
24
25
return unique_items
0 commit comments