1.Kth Largest Element in an Array
Solution : (using Max Heap)
class Solution
{
public:
int findKthLargest(vector<int> &nums, int k)
{
make_heap(nums.begin(),nums.end());
int j = 0;
while (j < k - 1)
{
pop_heap(nums.begin(),nums.end());
nums.pop_back();
j++;
}
return nums.front();
}
};Solution: (Using Priority Queue)
Solution: (Quick Select)
Last updated