宝马娱乐在线112222 > 网络应用 > 215. Kth Largest Element in an Array,kthlargest

原标题:215. Kth Largest Element in an Array,kthlargest

浏览次数:99 时间:2019-11-02

215. Kth Largest Element in an Array,kthlargest

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.

1 public class Solution {
2     public int findKthLargest(int[] nums, int k) {
3         Arrays.sort(nums);
4         return nums[nums.length-k];
5     }
6 }

 

http://www.bkjia.com/Javabc/1131892.htmlwww.bkjia.comtruehttp://www.bkjia.com/Javabc/1131892.htmlTechArticle215. Kth Largest Element in an Array,kthlargest Find thekth largest element in an unsorted array. Note that it is the kth largest element in the sorted order, not the kth distinc...

本文由宝马娱乐在线112222发布于网络应用,转载请注明出处:215. Kth Largest Element in an Array,kthlargest

关键词:

上一篇:CentOS7基于虚拟用户的vsftpd宝马娱乐在线112222

下一篇:没有了