C++ and Go Solutions for Finding the Kth Largest Element in an Array
"class Solution {\npublic:\n int findKthLargest(vector<int>& nums, int k){\n\t\tnth_element(nums.begin(),nums.begin()+k-1,nums.end(),greater<int>());\n return nums[k-1];\n }\n};"//转换为Go 内容:import "sort"\n\nfunc findKthLargest(nums []int, k int) int {\n sort.Slice(nums, func(i, j int) bool {\n return nums[i] > nums[j]\n })\n return nums[k-1]\n}
原文地址: https://www.cveoy.top/t/topic/qbFl 著作权归作者所有。请勿转载和采集!