int findLeader(int n, int* x){
int leader = x[0], c = 1, i;
for(i=1; i n/2) return leader;
else return NULL;
}
}
I'm not the author of this code, but this will work for your problem. The first part looks for a potential leader, the second checks if it appears more than n/2 times in the array.