class Solution { public int findKthLargest(int[] nums, int k) { if (nums.length == 0) { return 0; } return findKth(nums, 0, nums.length - 1, nums.length - k); } private int findKth(int[] nums, int start, int end, int k) { if (start > end) { return -1; } int pivot = nums[end]; int runner = start; for (int i = start; i < end; i++) { if (nums[i] <= pivot) { swap(nums, i, runner++); } } swap(nums, runner, end); if (runner == k) { return nums[runner]; } else if (runner < k) { return findKth(nums, runner + 1, end, k); } return findKth(nums, start, runner - 1, k); } private void swap(int[] nums, int i, int j) { int tmp = nums[i]; nums[i] = nums[j]; nums[j] = tmp; }}