Kth Largest Element in an Array
来源:互联网 发布:linux yum安装snmp 编辑:程序博客网 时间:2024/05/23 22:22
这道题我们先用heap做了,之后再用排序的方法处理。
public class Solution { public int findKthLargest(int[] nums, int k) { PriorityQueue<Integer> queue = new PriorityQueue<>(); for (int i : nums) { queue.offer(i); if (queue.size() > k) { queue.poll(); } } return queue.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
- Plus One
- Implement Queue using Stacks
- Power of Four
- 陶哲轩实分析-第14章 一致收敛
- 欢迎使用CSDN-markdown编辑器
- Kth Largest Element in an Array
- leecode_307 Range Sum Query - Mutable
- HTTP协议详解(转载)
- Letter Combinations of a Phone Number
- Pascal's Triangle
- Remove Duplicates from Sorted Array
- Increasing Triplet Subsequence
- Binary Tree Level Order Tranversal
- 了解流程类型,第 3 篇:动态消息广告