# 217. Contains Duplicate



use HashSet

```java
class Solution {
    public boolean containsDuplicate(int[] nums) {
        Set<Integer> set = new HashSet<>();
        for (int num : nums) {
            set.add(num);
        }
        return set.size() != nums.length;
    }
}


/*
use set
T: O(n)
S: O(n)

*/
```



use sort

```java
class Solution {
    public boolean containsDuplicate(int[] nums) {
        Arrays.sort(nums);
        for (int i = 1; i < nums.length; i++) {
            if (nums[i] == nums[i-1]) {
                return true;
            }
        }
        return false;
    }
}


/*
use set
T: O(n)
S: O(n)

use sort
T: O(nlogn)
S: O(1)
*/
```
