classSolution { publicintfindKthLargest(int[] nums, int k) { intstart=0, end = nums.length - 1; while (start <= end) { intp= partition(nums, start, end); if (p == k - 1) { return nums[p]; } if (p > k - 1) { end = p - 1; } if (p < k - 1) { start = p + 1; } } return -1; } privateintpartition(int[] nums, int s, int e) { if (s == e) return s; intp= nums[e]; inti= s - 1, j = s; //loop invariant, left of i is all smaller than p, including i. between i and j are all bigger than p while (j < e) { if (nums[j] > p) { i++; swap(nums, i, j); } j++; } swap(nums, i+1, e); return i + 1; } privatevoidswap(int[] nums, int i, int j) { inttemp= nums[i]; nums[i] = nums[j]; nums[j] = temp; } }