Skip to content

Commit

Permalink
Merge pull request neetcode-gh#950 from notauserx/703-Kth-Largest-Ele…
Browse files Browse the repository at this point in the history
…ment-In-A-Stream.cs

create 703-Kth-Largest-Element-In-A-Stream.cs
  • Loading branch information
Ahmad-A0 authored Aug 27, 2022
2 parents e34ee82 + 85266e2 commit e92034c
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions csharp/703-Kth-Largest-Element-In-A-Stream.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
public class KthLargest {
PriorityQueue<int, int> data = new PriorityQueue<int, int>();
int k;

public KthLargest(int k, int[] nums) {
this.k = k;
foreach(var num in nums)
Add(num);
}

public int Add(int val) {
data.Enqueue(val, val);

if(data.Count > k)
data.Dequeue();

return data.Peek();
}
}

0 comments on commit e92034c

Please sign in to comment.