leetcode刷题,总结,记录,备忘 215
2016-01-12 19:55
393 查看
leetcode215Kth 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
Note:
You may assume k is always valid, 1 ≤ k ≤ array's length.
简单题,就不多赘述了。
class Solution {
public:
int findKthLargest(vector<int>& nums, int k) {
sort(nums.begin(), nums.end());
return nums[nums.size() - k];
}
};
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(vector<int>& nums, int k) {
sort(nums.begin(), nums.end());
return nums[nums.size() - k];
}
};
相关文章推荐
- mysql进阶(二十一)删除表数据
- Android开发 - 下拉刷新和分段头悬停列表
- mysql进阶(二十一)删除表数据
- 判断Char是否为数字
- linux添加用户和修改密码
- CodeForcess--609B--The Best Gift(模拟水题)
- hdu 5101 Select(Bestcoder Round #17)
- CodeForcess--609B--The Best Gift(模拟水题)
- BZOJ2002 [Hnoi2010]Bounce 弹飞绵羊
- erlang的shell历史记录
- Android系统设置【android.provider.settings】
- 如何更改linux文件的拥有者及用户组(chown和chgrp)
- C++的函数重载
- 【主席树】BZOJ 1146 network网络管理
- Ofbiz之皮肤主题开发定制
- SVN:TortoiseSVN客户端重新设置用户名和密码
- list!=null和list.size()>0的区别
- 文件状态信息
- 关于动态布局的时候调整布局的错误(一)
- android的adb命令