The Find K - th largest element in an array.
Notice: You can swap elements in the array
Found in the array element
the first k
Note: you can swap the position of the element in the array
[title link]
http://www.lintcode.com/en/problem/kth-largest-element/
[title]
Sort: a start to see this problem certainly feel very simple, as long as the sort, then return the index value of specific is ok, but the sort of time complexity is O (nlogn)
at least
The Quick Select: this is a Quick sort, use the partition part, each choose a pivot, less than the put on the left side of it, is greater than its put on the right,
With Quick Sort of divide and conquer method, or in the Priority Queue (Max Heap) data structures, Java and Python are all minimum Heap, need to change my
Answer [subject]
http://www.jiuzhang.com/solutions/kth-largest-element/
CodePudding user response:
Resulted from solution by using the List controls: set of List2 Sorted=TrueThis example from 100 random Numbers to find out the big number 5,
List2. List (0) is the problem of the solution,
Private Const K=5
Private Const N=100
Private Sub Command1_Click ()
Dim As Integer I
'Prerare data
List1. Clear
Randomize
For I=1 To N
List1. AddItem Rnd * 1000
Next I
'the Find Kth Largest Number
List2. Clear
For I=0 To N - 1
If List2. ListCount & lt; K Then
List2. AddItem List1. List (I)
The Else
If List1. List (I) & gt; List2. List (0) Then
List2. RemoveItem 0
List2. AddItem List1. List (I)
End the If
End the If
Next I
End Sub