查找数组中的元素多数 [英] Find majority element in array
本文介绍了查找数组中的元素多数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何发现大多数elelment在O型数组(N)?
how to find the majority elelment in an array in O(n)?
注意:大多数元件是一个发生超过一半的数组的大小
Note: The majority element is the element that occurs more than half of the size of the array
推荐答案
多数元件(如果存在)也将是中位数。我们可以在O(n)的中位数,然后检查其是否确实为O有效的大部分元素(N)。
The majority element (if it exists) will also be the median. We can find the median in O(n) and then check that it is indeed a valid majority element in O(n).
这篇关于查找数组中的元素多数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文