Skip to content

Commit 85266e2

Browse files
committed
create 703-Kth-Largest-Element-In-A-Stream.cs
1 parent f8912c5 commit 85266e2

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
public class KthLargest {
2+
PriorityQueue<int, int> data = new PriorityQueue<int, int>();
3+
int k;
4+
5+
public KthLargest(int k, int[] nums) {
6+
this.k = k;
7+
foreach(var num in nums)
8+
Add(num);
9+
}
10+
11+
public int Add(int val) {
12+
data.Enqueue(val, val);
13+
14+
if(data.Count > k)
15+
data.Dequeue();
16+
17+
return data.Peek();
18+
}
19+
}

0 commit comments

Comments
 (0)