• 문제 링크
Kth Largest Element in a Stream - LeetCode
Can you solve this real interview question? Kth Largest Element in a Stream - You are part of a university admissions office and need to keep track of the kth highest test score from applicants in real-time. This helps to determine cut-off marks for interv
leetcode.com
• 풀이 코드
import java.util.PriorityQueue;
public class KthLargest {
private final PriorityQueue<Integer> pq;
private final int k;
public KthLargest(int k, int[] nums) {
this.k = k;
this.pq = new PriorityQueue<>(k);
for (int num : nums) add(num);
}
public int add(int val) {
pq.offer(val);
if (pq.size() > k) pq.poll();
return pq.element();
}
}'Problem Solving > LeetCode' 카테고리의 다른 글
| [LeetCode] 705. Design HashSet - Java (0) | 2026.09.30 |
|---|---|
| [LeetCode] 704. Binary Search - Java (0) | 2026.09.29 |
| [LeetCode] 700. Search in a Binary Search Tree - Java (0) | 2026.09.27 |
| [LeetCode] 697. Degree of an Array - Java (0) | 2026.09.26 |
| [LeetCode] 696. Count Binary Substrings - Java (0) | 2026.09.25 |
댓글