如何利用小游戏开发框架提升企业小程序的用户体验与运营效率
593
2022-09-04
215. Kth Largest Element in an Array
Find the kth largest element in an unsorted array. Note that it is the kth largest element in the sorted order, not the kth distinct element.
For example, Given [3,2,1,5,6,4] and k = 2, return 5.
Note: You may assume k is always valid, 1 ≤ k ≤ array’s length.
class Solution { public int findKthLargest(int[] nums, int k) { Arrays.sort(nums); return nums[nums.length - k]; }}
class Solution: def findKthLargest(self, nums: List[int], k: int) -> int: return (sorted(nums)[-k])
/** * @param {number[]} nums * @param {number} k * @return {number} */var findKthLargest = function(nums, k) { return nums.sort((a,b) => b-a)[k-1];};
class Solution: def findKthLargest(self, nums: List[int], k: int) -> int: heapify(nums) return nlargest(k, nums)[-1]
/** * @param {number[]} nums * @param {number} k * @return {number} */var findKthLargest = function(nums, k) { var num = nums.sort((a,b) => a - b) return num[nums.length - k]};
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~