215. Kth Largest Element in an Array
Medium
Problem:
Input: nums = [3,2,1,5,6,4], k = 2
Output: 5Solution:
347. Top K Frequent Elementsheapq
class Solution:
def findKthLargest(self, nums: List[int], k: int) -> int:
heap = list()
for n in nums:
heapq.heappush(heap, -n)
for _ in range(k):
heapq.heappop(heap)
return -heapq.heappop(heap)heapq.heapify
heapq.nlargest
Sorting
Summary:
Last updated