###### [leetcode] 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.

Solution:

Idea: sort numbers first, and than check consecutive elements. However, the complexity of sorting depends on sorting algorithm.

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

for (int i = 0; i < nums.size() -1; i++){
if ((nums[i] - nums[i+1])==0)
return true;
}
return false;
}
};

#### leetcode 217 Contains Duplicate 数组中是否有重复的数字

2015-08-09 21:48:10

#### LeetCode 217. Contains Duplicate（C++版）

2017-03-31 11:16:32

#### LeetCode 217:Contains Duplicate

2015-05-31 18:37:10

#### leetcode 217: Contains Duplicate

2015-06-05 08:27:02

#### 【LeetCode-面试算法经典-Java实现】【217-Contains Duplicate（包含重复元素）】

2015-08-28 07:00:49

#### leetcode【217+219 Contains Duplicate I+II】【python】

2016-09-08 10:33:49

#### leetcode_c++：Contains Duplicate II(219)

2016-06-18 13:33:40

#### 219. Contains Duplicate II [easy] (Python)

2016-06-14 19:59:14

#### 217. Contains Duplicate [easy] (Python)

2016-05-14 19:39:50

#### leetcode_c++：Contains Duplicate(217)

2016-06-18 12:40:29

## 不良信息举报

[leetcode] 217. Contains Duplicate