class Solution { public: int findKthLargest(vector<int>& nums, int k) { sort(nums.begin(), nums.end()); return nums[nums.size() - k]; } };
补充python的实现,使用堆排序:
1 import heapq 2 class Solution: 3 def findKthLargest(self, nums: 'List[int]', k: 'int') -> 'int': 4 lists = heapq.nlargest(k,nums) 5 return lists[-1]