int getkey(int* a, int left, int right)
{
int mid = (left + right) / 2;
if (a[left] > a[right])
{
if (a[mid] < a[right])
{
return right;
}
else if (a[mid] < a[left])
{
return mid;
}
else
{
return left;
}
}
else
{
if (a[mid] < a[left])
{
return left;
}
else if (a[mid] < a[right])
{
return mid;
}
else
{
return right;
}
}
}
void fastsort(int* a, int begin, int end)
{
if (begin >= end)
{
return;
}
int left = begin;
int right = end;
int cur = left + 1;
int mid = getkey(a, left, right);
int c = a[left];
a[left] = a[mid];
a[mid] = c;
int key = a[left];
while (cur <= right)
{
if (a[cur] < key)
{
int d = a[left];
a[left] = a[cur];
a[cur] = d;
left++;
cur++;
}
else if (a[cur] > key)
{
int e = a[right];
a[right] = a[cur];
a[cur] = e;
--right;
}
else
{
cur++;
}
}
fastsort(a, begin, left - 1);
fastsort(a, right + 1, end);
}
bool containsDuplicate(int* nums, int numsSize){
fastsort(nums,0,numsSize-1);
for(int i=1;i<numsSize;i++)
{
if(nums[i]==nums[i-1])
{
return true;
}
}
return false;
}
本题有巨量数据和针对快排的数据,所以要用三路分治秒文章来源地址https://www.toymoban.com/news/detail-827283.html
文章来源:https://www.toymoban.com/news/detail-827283.html
到了这里,关于力扣坑题:存在重复元素的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!