-
Initialize Data Structure: Create an empty set or hashmap to store unique elements encountered so far. This data structure efficiently handles uniqueness checks due to its inherent property of rejecting duplicates.
-
Iterate through the List:
- For each element in the list:
- Check for Duplication: If the element already exists in the set or hashmap, it's a duplicate. Return True immediately, signaling that duplicates have been found.
- Add to Unique Elements: If the element is not found (not a duplicate), add it to the set or hashmap to track it as potentially unique.
- For each element in the list:
-
No Duplicates Found: If the entire list is iterated through without returning True, it means no duplicates were encountered. Return False to indicate a unique list.
217. Contains Duplicate
Folders and files
Name | Name | Last commit date | ||
---|---|---|---|---|
parent directory.. | ||||