leetcode 215. Kth Largest Element in an Array
来源:互联网 发布:淘宝店铺名片上的店名 编辑:程序博客网 时间:2024/05/17 11:37
难度:midium
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.
class Solution {public: int findindex(vector<int>&nums) { int length=nums.size(); int num=nums[0]; int index=0; for(int i=0;i<length;i++) { if(nums[i]>=num) { num=nums[i]; index=i; } } return index; } int findKthLargest(vector<int>& nums, int k) { vector<int>temp=nums; int length=temp.size(); int number=0; for(int i =0;i<k;i++) { int index=findindex(temp); number=temp[index]; temp[index]=-1000; } return number; }};
题解:说实话好像没有用到divide-and-conquere。。。嘻嘻
直接寻找k次最大的元素 然后将此元素置为0
然后输出最后一次找到的元素
0 0
- Leetcode Kth Largest Element in an Array
- Leetcode: Kth Largest Element in an Array
- LeetCode Kth Largest Element in an Array
- [LeetCode] Kth Largest Element in an Array
- [leetcode] Kth Largest Element in an Array
- leetcode--Kth Largest Element in an Array
- #leetcode#Kth Largest Element in an Array
- LeetCode Kth Largest Element in an Array
- 【Leetcode】Kth Largest Element in an Array
- Leetcode: Kth Largest Element in an Array
- Kth Largest Element in an Array -- leetcode
- [Leetcode]Kth Largest Element in an Array
- [LeetCode]Kth Largest Element in an Array
- *LeetCode-Kth Largest Element in an Array
- LeetCode----Kth Largest Element in an Array
- LeetCode Kth Largest Element in an Array
- leetcode-Kth Largest Element in an Array
- LeetCode -- Kth Largest Element in an Array
- Foundation of Machine Learning 笔记第二部分——Guarantees for Finite Hypothesis Sets in Consistent Case
- JFinal笔记day01
- ViewGroup与View的事件分发机制
- PWM
- Windows2012 要远程登录,你需要具有通过远程桌面服务进行登录的权限.
- leetcode 215. Kth Largest Element in an Array
- 7Liveasia Casino 200% Slots Welcome Bonus
- 内部类、访问权限课堂笔记
- HashMap 多线程处理之 Fail-Fast机制
- d3js的初接触
- HBase1.2.4新版api操作示例
- 应聘技巧(所有行业都可以使用的技巧。个人看法)
- 差分约束(个人理解)
- JS命名空间