algorithm - Find the majority element in array -


the majority element element occurs more half of size of array.

how find majority element in array in o(n)?

example input:

{2,1,2,3,4,2,1,2,2} 

expected output:

2 

the majority element (if exists) median. can find median in o(n) , check indeed valid majority element in o(n). more details implementation link


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -