[leedcode 215] Kth Largest Element in an Array
2015-08-06 21:04
253 查看
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.
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.
public class Solution { public int findKthLargest(int[] nums, int k) { //先排序,然后返回第k个值(从小到大排序) Arrays.sort(nums); return nums[nums.length-k]; } }
相关文章推荐
- CentOS、Mysql性能分析
- 关于英雄联盟“服务器繁忙 暂时无法登录 请稍候再试”的解决方法
- UVA 11134
- matlab基础学习笔记
- Java中变量的作用域
- 图像处理和计算机视觉中的经典论文
- [转]MS SQL数据库备份和恢复存储过程
- JAX-WS编写webservice
- WebView之2
- 超级楼梯
- 视频转换和视频直播
- php5中的clone 浅拷贝 深拷贝
- java中关于方法重载和renturn用法
- poj2251 dungeon master【BFS】~
- 《机器学习》(Machine Learning)——Andrew Ng 斯坦福大学公开课学习笔记(二)
- 设计模式入门--观察者模式
- bitcask
- 如何获取XML
- Single Number
- POJ 3694 Network