[LeetCode]215. Kth Largest Element in an Array
2016-03-15 09:38
183 查看
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
Note:
You may assume k is always valid, 1 ≤ k ≤ array's length.
思路:对数组进行排序,选择第k个返回
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.
思路:对数组进行排序,选择第k个返回
public class Solution { public int findKthLargest(int[] nums, int k) { Arrays.sort(nums); return nums[nums.length-k]; } }
相关文章推荐
- 学习scala的点点滴滴(2)-与java交互
- 【转】MySQL编码问题
- 思考人生
- GSM模块通过国家网络授时中心获取网络时间同步
- YII Framework框架使用YIIC快速创建YII应用之migrate用法实例详解
- CPU中的三类总线
- DWZ框架checkbox全选功能失败的解决方法
- [期望DP] BZOJ4008 [HNOI2015]亚瑟王
- 美团在Redis上踩过的一些坑-3.redis内存占用飙升
- 美团在Redis上踩过的一些坑-2.bgrewriteaof问题
- JSON与XML的区别比较
- tcp三次握手 redis 连接超时
- Android面向HTTP协议发送post请求
- plsql强制关闭后再打开提示已停止工作的解决办法
- linux系统内SAMBA共享问题
- iPhone手机录像步骤
- [国嵌攻略][146][块设备驱动实例分析]
- IE8的select
- iOS检测网络状态
- Eclipse问题 A cycle was detected in the build path of project: XXX