We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
class Solution { public int findKthLargest(int[] nums, int k) { // 快速排序 小的放到右边,大的放到左边即可 quickSort(nums, 0, nums.length - 1); return nums[k - 1]; } public int[] quickSort(int[] nums, int left, int right) { if (left >= right) { return null; } int pivot = partion(nums, left, right); quickSort(nums, left, pivot - 1); quickSort(nums, pivot + 1,right); return nums; } public int partion(int[] nums, int left, int right) { int pivot = nums[left]; while (left < right) { while (left < right && nums[right] <= pivot) { right--; } nums[left] = nums[right]; while (left < right && nums[left] >= pivot) { left++; } nums[right] = nums[left]; } nums[left] = pivot; return left; } }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
[215. 数组中的第K个最大元素](https://leetcode.cn/problems/kth-largest-element-in-an-array/)
The text was updated successfully, but these errors were encountered: