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.
1 int majorityElement(int* nums, int numsSize) 2 { 3 if(numsSize==1) 4 return nums[0]; 5 6 7 int i,j,k; 8 for(i=1;i=0;j--)11 {12 if(nums[i]>=nums[j])13 break;14 }15 16 if(i!=j-1)17 {18 int temp=nums[i];19 for(k=i-1;k>j;k--)20 {21 nums[k+1]=nums[k];22 }23 nums[k+1]=temp;24 }25 }26 27 int Time;28 Time=numsSize/2;29 int count=1;30 for(i=0;i Time)36 {37 return nums[i];38 }39 }40 else41 {42 count=1;43 }44 }45 46 47 return 0;48 }