#include <stdio.h>
#include <stdlib.h>
int Find(int *ID, int N)
{
int candidate = 0;
int nTimes, i;
for(i = nTimes = 0; i < N; i++)
{
if(nTimes == 0)
{
int tt = ID[i];
candidate = ID[i], nTimes = 1;
}
else
{
if(candidate == ID[i])
{
nTimes++;
}
else
{
nTimes--;
}
}
}
return candidate;
}
int main()
{
int ID[5] = {1, 2, 2, 0, 2};
int candidate = Find(ID, 5);
printf("candidate = %d\n", candidate);
return 0;
}
#include <stdlib.h>
int Find(int *ID, int N)
{
int candidate = 0;
int nTimes, i;
for(i = nTimes = 0; i < N; i++)
{
if(nTimes == 0)
{
int tt = ID[i];
candidate = ID[i], nTimes = 1;
}
else
{
if(candidate == ID[i])
{
nTimes++;
}
else
{
nTimes--;
}
}
}
return candidate;
}
int main()
{
int ID[5] = {1, 2, 2, 0, 2};
int candidate = Find(ID, 5);
printf("candidate = %d\n", candidate);
return 0;
}