Kth Largest Element in an Array
来源:互联网 发布:武汉java工资一般多少 编辑:程序博客网 时间:2024/06/07 01:38
题目链接
思路:优先级树
java里面优先级树使用的是PriorityQueue
要传入一个比较因子。这个因子对于优先级高的返回-1;
public class Solution { public int findKthLargest(int[] nums, int k) { Comparator<Integer> OrderIsdn = new Comparator<Integer>(){ public int compare(Integer o1, Integer o2) { if(o1>o2) { return -1; } else if(o1<o2) { return 1; } else { return 0; } } }; PriorityQueue<Integer> pQueue=new PriorityQueue<Integer>(OrderIsdn); for(int i=0;i<nums.length;i++) { pQueue.add(nums[i]); } for(int i=0;i<k-1;i++) { pQueue.poll(); } return pQueue.peek(); }}
0 0
- Kth Largest Element in an Array
- Leetcode Kth Largest Element in an Array
- Kth Largest Element in an Array
- 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] Kth Largest Element in an Array
- Kth Largest Element in an Array
- Kth Largest Element in an Array
- leetcode--Kth Largest Element in an Array
- Kth Largest Element in an Array
- 215.Kth Largest Element in an Array
- #leetcode#Kth Largest Element in an Array
- LeetCode Kth Largest Element in an Array
- LeetCode215:Kth Largest Element in an Array
- Kth Largest Element in an Array
- 新的领域----舞动你的生活
- 如何打开Galaxy S4的USB调试
- Codeforces 148 D Bag of mice
- hdu 2476 区间dp
- 用jquery实现小火箭到页面顶部的效果
- Kth Largest Element in an Array
- HDU 1671 — Phone List
- 字符串 专题训练 · 最长回文子串之Manacher算法
- UI高级之事件的响应者链
- 分布式存储引擎
- android开发步步为营之71:CoordinatorLayout+AppBarLayout+RecyclerView+ViewPager打造可上下左右滑动的App主框架
- Valid Anagram
- Unity插件之TDTK的学习之超萌怪物(四)
- linux学习之路(1)