Contains Duplicate
Input: [1,2,3,1]
Output: true
Input: [1,2,3,4]
Output: false
Input: [1,1,1,3,3,4,3,2,4,2]
Output: trueSolutions
π§ Cpp
Last updated
Input: [1,2,3,1]
Output: true
Input: [1,2,3,4]
Output: false
Input: [1,1,1,3,3,4,3,2,4,2]
Output: trueLast updated
#include <algorithm>
class Solution {
public:
bool containsDuplicate(vector<int> nums)
{
std::sort(nums.begin(), nums.end());
if(
nums.size()
==
std::distance( nums.begin(), std::unique(nums.begin(), nums.end()) )
)
return false;
else
return true;
}
};