Skip to content

Latest commit

 

History

History

217. Contains Duplicate

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

Intuitive Explanation:

Algorithm:

  1. 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.

  2. 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.
  3. 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.