---
# System prepended metadata

title: 217. Contain Duplicate
tags: [Leetcode, Array, Easy]

---

# 217. Contain Duplicate
###### tags: `Leetcode` `Easy` `Array`
Link: https://leetcode.com/submissions/detail/548193708/
## 思路
### 思路一
先排序，然后如果有重复的就可以找到了
### 思路二
哈希表
## Code
### 思路一
```java=
class Solution {
    public boolean containsDuplicate(int[] nums) {
        Arrays.sort(nums);
        for(int i = 0;i < nums.length-1;i++){
            if(nums[i] == nums[i+1]){
                return true;
            }
        }
        return false;
    }
}
```
### 思路二
```java=
class Solution {
    public boolean containsDuplicate(int[] nums) {
        Set<Integer> set = new HashSet<Integer>();
        for(int x : nums){
            if(!set.add(x)){
                return true;
            }
        }
        return false;
    }
}
```
### Result
### 思路一
Your runtime beats **27.55 %** of java submissions.
Your memory usage beats **21.91 %** of java submissions.
### 思路二
Runtime: 4 ms, faster than **82.36%** of Java online submissions for Contains Duplicate.
Memory Usage: 42.9 MB, less than **75.74%** of Java online submissions for Contains Duplicate.
