且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在寻找一个数组的第n个最大元素

更新时间:2022-12-11 08:19:01

查找第k个最大的元素,使用选择算法
结果接下来,遍历数组,发现这是更大的所有元素/平等的。

Find the kth biggest element, using selection algorithm.
Next, iterate the array and find all elements which are larger/equal it.

的复杂性:作为选择和O(N)为迭代O(N),所以总也为O(n)

complexity: O(n) for selection and O(n) for iterating, so the total is also O(n)