Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit ebe2626

Browse filesBrowse files
committed
Create README - LeetHub
1 parent 85393c0 commit ebe2626
Copy full SHA for ebe2626

File tree

1 file changed

+39
-0
lines changed
Filter options

1 file changed

+39
-0
lines changed
+39Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<h2><a href="https://leetcode.com/problems/kth-largest-element-in-a-stream/">703. Kth Largest Element in a Stream</a></h2><h3>Easy</h3><hr><div><p>Design a class to find the <code>k<sup>th</sup></code> largest element in a stream. Note that it is the <code>k<sup>th</sup></code> largest element in the sorted order, not the <code>k<sup>th</sup></code> distinct element.</p>
2+
3+
<p>Implement <code>KthLargest</code> class:</p>
4+
5+
<ul>
6+
<li><code>KthLargest(int k, int[] nums)</code> Initializes the object with the integer <code>k</code> and the stream of integers <code>nums</code>.</li>
7+
<li><code>int add(int val)</code> Appends the integer <code>val</code> to the stream and returns the element representing the <code>k<sup>th</sup></code> largest element in the stream.</li>
8+
</ul>
9+
10+
<p>&nbsp;</p>
11+
<p><strong>Example 1:</strong></p>
12+
13+
<pre><strong>Input</strong>
14+
["KthLargest", "add", "add", "add", "add", "add"]
15+
[[3, [4, 5, 8, 2]], [3], [5], [10], [9], [4]]
16+
<strong>Output</strong>
17+
[null, 4, 5, 5, 8, 8]
18+
19+
<strong>Explanation</strong>
20+
KthLargest kthLargest = new KthLargest(3, [4, 5, 8, 2]);
21+
kthLargest.add(3); // return 4
22+
kthLargest.add(5); // return 5
23+
kthLargest.add(10); // return 5
24+
kthLargest.add(9); // return 8
25+
kthLargest.add(4); // return 8
26+
</pre>
27+
28+
<p>&nbsp;</p>
29+
<p><strong>Constraints:</strong></p>
30+
31+
<ul>
32+
<li><code>1 &lt;= k &lt;= 10<sup>4</sup></code></li>
33+
<li><code>0 &lt;= nums.length &lt;= 10<sup>4</sup></code></li>
34+
<li><code>-10<sup>4</sup> &lt;= nums[i] &lt;= 10<sup>4</sup></code></li>
35+
<li><code>-10<sup>4</sup> &lt;= val &lt;= 10<sup>4</sup></code></li>
36+
<li>At most <code>10<sup>4</sup></code> calls will be made to <code>add</code>.</li>
37+
<li>It is guaranteed that there will be at least <code>k</code> elements in the array when you search for the <code>k<sup>th</sup></code> element.</li>
38+
</ul>
39+
</div>

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.