Python Heap nlogk Solution


  • 1
    Y
    from heapq import heappop, heappush, heapify
    
    def findKthLargest(self, nums, k):
            heap = []
            for i in nums:
                heappush(heap, i)
                if len(heap) > k:
                    heappop(heap)
            return heap[0]

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.