题目:
Find the kth largest element in an unsorted array. Note that it is the kth largest element in the sorted order, not the kth distinct element.
说实话这道题我还是挺迷惑的,因为题目并没有要求不能排序,所以不知道为啥还有medium的难度 。
class Solution {
public:
int findKthLargest(vector<int>& nums, int k) {
sort(begin(nums), end(nums));
return nums[nums.size()-k];
}
};
博客围绕LeetCode题目展开,题目要求在未排序数组中找出第k大元素,这里的第k大是排序后的第k大,而非第k个不同元素。博主对题目难度为中等表示疑惑,因题目未限制不能排序。

6809

被折叠的 条评论
为什么被折叠?



