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
Post a Comment