## 翻译

``````给定一个整型数字数组，找出这个数组是否包含任何重复内容。

## 原文

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

## 分析

``````bool containsDuplicate(vector& nums) {
vector::iterator temp;
int num_to_find;
for (vector::iterator index = nums.begin(); index < nums.end(); ++index) {
num_to_find = *index;
temp = std::find(index + 1, nums.end(), num_to_find);
if (temp != nums.end())
return true;
}
return false;
}``````

``````bool containsDuplicate(vector& nums) {
sort(nums.begin(), nums.end());
vector::iterator temp;
int num_to_find;
for (vector::iterator index = nums.begin(); index < nums.end(); ++index) {
num_to_find = *index;
temp = std::find(index + 1, nums.end(), num_to_find);
if (temp != nums.end())
return true;
}
return false;
}``````

``````current == next  说明什么？重复了呗！
current < next 说明什么？我都排过序了啊，这不是妥妥的嘛？不用判断这个了。
current > next 说明什么？都说了已经排过序了，这可能吗！``````

``````bool containsDuplicate(vector& nums) {
if (nums.size() <= 1)
return false;
sort(nums.begin(), nums.end());
vector::iterator temp;
int num_to_find;
for (vector::iterator it = nums.begin(), temp = it + 1; it < nums.end(); ++it,++temp) {
if (*temp == *it)   return true;
}
return false;
}``````

``````temp = it + 1;
++ temp;``````

``````bool containsDuplicate(vector& nums) {
if (nums.size() <= 1)
return false;
sort(nums.begin(), nums.end());
vector::iterator temp;
int num_to_find;
for (vector::iterator it = nums.begin(); it < nums.end(); ++it) {
temp = it + 1;
if (*temp == *it) return true;
}
return false;
}``````

## 代码

``````class Solution {
public:
bool containsDuplicate(vector& nums) {
if (nums.size() <= 1)
return false;
sort(nums.begin(), nums.end());
vector::iterator temp;
int num_to_find;
for (vector::iterator it = nums.begin(); it < nums.end(); ++it) {
temp = it + 1;
if (*temp == *it) return true;
}
return false;
}
};``````

## 进阶

``````class Solution {
public:
bool containsDuplicate(vector& nums) {
if(nums.size() == 0)    return false;

int min = nums[0], max = nums[0];
for(auto n : nums){
if(n > max)     max = n;
if(n < min)    min = n;
}

int arr[max - min + 1] = {0};
for(auto n : nums){
++arr[n - min];
}

for(int i = 0; i != (max - min + 1); ++i)
if(arr[i] > 1)  return true;
return false;
}
};``````

``````class Solution {
public:
bool containsDuplicate(vector& nums) {
if (nums.size() == 0)    return false;
sort(nums.begin(), nums.end());
int min = nums[0], max = nums[nums.size() - 1];

int arr[max - min + 1] = { 0 };
for (auto n : nums) {
++arr[n - min];
}

for (int i = 0; i != (max - min + 1); ++i)
if (arr[i] > 1)  return true;
return false;
}
};``````

hash

``````class Solution {
public:
bool containsDuplicate(vector& nums) {
int count=1000;
vector hash[count];
for(int i=0;i=0?nums[i]:-nums[i])%count;
for(int j=0;j``````