# 217 Contains Duplicate

Given an array of integers, find if the array contains any duplicates. Your function should return true if any value appears at least twice in the array, and it should return false if every element is distinct.

**The Idea:** Use a hash set to confirm duplicates.

**Complexity:** O(n) time and space

```cpp
bool containsDuplicate(vector<int>& nums) {
    if (nums.empty()) return false;

    unordered_set<int> unique;
    unique.reserve(nums.size());

    for (int i : nums) {
        if (unique.find(i) == unique.end()) 
            unique.insert(i);
        else return true;
    }

    return false;
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://maksimdan.gitbook.io/interview-practice-problems/leetcode_sessions/217-contains-duplicate.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
