Turns out the simplest solution has the fastest running time


  • 0
    I

    So I have been looking for the solutions in discussion, and have been trying out many other solutions, like sort array and find kth index, quick select, selection sort and etc. Turns out sort the array and find the kth largest element has the best running time 81.92% versus quick select 25.86%.

    Anyway, it's good to know more than less :)

    BTW, Java code here ---

    public int findKthLargest(int[] nums, int k) {
        Arrays.sort(nums);
        return nums[nums.length - k];
    }

  • 1
    O

    I think it's unbelievable that quick select is slower than Arrays.sort.
    The possible reason may be that you use a fix index as the pivot.
    As my quick select, it just takes 2ms and beat 97%


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.