标签:
利用最小堆解决,代码如下:
class Solution(object): def findKthLargest(self, nums, k): """ :type nums: List[int] :type k: int :rtype: int """ heap=nums[0:k] heapq.heapify(heap) l=len(nums) for i in xrange(k,l): heapq.heappushpop(heap,nums[i]) return heap[0]
Kth Largest Element in an Array
标签:
原文地址:http://www.cnblogs.com/sherylwang/p/5426669.html