#215

Kth Largest Element in an Array

pupil · 575 · lc medium +29 · verified · 68.8% accepted · 18,688 likes · top 76%

play →

Description

Find the k-th largest value (in sorted order, counting duplicates) in the integer array nums and return it. Can you avoid a full sort?

Example 1:

Input: nums = [3,2,1,5,6,4], k = 2
Output: 5

Example 2:

Input: nums = [3,2,3,1,2,4,5,5,6], k = 4
Output: 4

Code

1
2
3