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.
class Solution {
public:
bool containsDuplicate(vector<int>& nums) {
sort(nums.begin(),nums.end());
int count=0;
if(nums.empty())
return false;
if(nums.size()!=1)
{
for(int i=0;i<nums.size()-1;i++)
{
if(nums[i]!=nums[i+1])
count++;
}
}
else
return false;
if(count==nums.size()-1)
return false;
else
return true;
}
};