# 217.Contains Duplicate

**217.Contains Duplicate**

难度:Easy

> 给定一个整数数组，判断是否存在重复元素。

如果任何值在数组中出现至少两次，函数返回 true。如果数组中每个元素都不相同，则返回 false。

```
示例 1:

输入: [1,2,3,1]
输出: true
示例 2:

输入: [1,2,3,4]
输出: false
示例 3:

输入: [1,1,1,3,3,4,3,2,4,2]
输出: true
```

主要方式是计数，可以通过集合来解决。

```
class Solution {
public:
    bool containsDuplicate(vector<int>& nums) {
        unordered_set<int>map(nums.begin(), nums.end());
        return map.size() < nums.size();
    }
};
```

> 执行用时 :92ms, 在所有 C++ 提交中击败了20.51%的用户\
> 内存消耗 :16MB, 在所有 C++ 提交中击败了54.20%的用户


---

# 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://dfine.gitbook.io/leetcode/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.
