class Solution {\npublic:\n int findKthLargest(vector& nums, int k){\n\t\tnth_element(nums.begin(),nums.begin()+k-1,nums.end(),greater());\n return nums[k-1];\n }\n};//转换为Swift内容:class Solution {\n func findKthLargest(_ nums: [Int], _ k: Int) -> Int {\n var sortedNums = nums.sorted(by: >)\n return sortedNums[k-1]\n }\n}

C++ 和 Swift 实现寻找数组中第 k 大元素 - 代码对比

原文地址: https://www.cveoy.top/t/topic/qbFc 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录