```
void swap(vector<int>& nums, int l, int r){
int temp = nums[l];
nums[l] = nums[r];
nums[r] = temp;
}
int findKthLargest(vector<int>& nums, int k) {
int sz = nums.size();
int l = 0, r = sz-1;
while(l<r){
int tail = l, curr = l+1;
while(curr<=r){
if(nums[curr]>=nums[l]) swap(nums, ++tail, curr);
curr++;
}
swap(nums, tail, l);
if(k == tail-l+1) return nums[tail];
else if(k<tail-l+1) r = tail-1;
else{
k -= (tail-l+1);
l = tail+1;
}
}
return nums[l];
}
```