privateintfindKthNum(int[] nums, int from, int to, int k) { intindex= to; intstart= from; intend= to; while (start < end) { if (nums[start] < nums[index]) { start++; continue; }
if (nums[end] >= nums[index]) { end--; continue; }
swap(nums, start, end); }
if (nums[start] > nums[index]) { swap(nums, start, index); }
if (to - start + 1 == k) { return nums[start]; }
if (to - start + 1 > k) { return findKthNum(nums, start + 1, to, k); }
return findKthNum(nums, from, start - 1, k - to + start - 1); }
privatevoidswap(int[] nums, int i, int j) { inttemp= nums[i]; nums[i] = nums[j]; nums[j] = temp; } }