Skip to main content

Kth Largest Element in an Array (Leetcode 215)

Leetcode 215

Given an integer array nums and an integer k, return the kth largest element in the array.

Note that it is the kth largest element in the sorted order, not the kth distinct element.

Solution 1

/**
* @param {number[]} nums
* @param {number} k
* @return {number}
*/

var findKthLargest = function(nums, k) {
nums.sort((a,b) => a - b).reverse();
return nums[k-1];
};

Can you solve it without sorting?

Coming soon...