classSolution { public: /** * @param n: An integer * @param nums: An array * @return: the Kth largest element */ staticboolcmp(int a, int b){ return a > b; } voidquicksort(vector<int>& a, int left, int right, int n) { int temp = a[left];
int i, j; i = left; j = right;
while (i < j) { while (i < j && a[j] <= temp) j--; a[i] = a[j]; while (i < j && a[i] >= temp) i++; a[j] = a[i];
} a[i] = temp;
if (i < n) { quicksort(a, i+1, right, n); } elseif (i > n) { quicksort(a, left, i - 1, n); } else {
sort(a.begin()+left, a.begin()+i+1, cmp); } }
intkthLargestElement(int n, vector<int>& nums) {
int l, r;
l = 0; r = nums.size() - 1; n--; quicksort(nums, l, r, n);