Given an array of size n, find the majority element. The majority element is the element that appears more than ⌊ n/2 ⌋
times.
You may assume that the array is non-empty and the majority element always exist in the array.
int majorityElement(int* nums, int numsSize)
{
if(numsSize==)
return nums[]; int i,j,k;
for(i=;i<numsSize;i++)
{
for(j=i-;j>=;j--)
{
if(nums[i]>=nums[j])
break;
} if(i!=j-)
{
int temp=nums[i];
for(k=i-;k>j;k--)
{
nums[k+]=nums[k];
}
nums[k+]=temp;
}
} int Time;
Time=numsSize/;
int count=;
for(i=;i<numsSize-;i++)
{
if(nums[i]==nums[i+])
{
count++;
if(count>Time)
{
return nums[i];
}
}
else
{
count=;
}
} return ;
}