mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-01-10 18:48:13 +08:00
21 lines
1.1 KiB
HTML
21 lines
1.1 KiB
HTML
<p>Imagine you are reading in a stream of integers. Periodically, you wish to be able to look up the rank of a number <code>x</code> (the number of values less than or equal to <code>x</code>). lmplement the data structures and algorithms to support these operations. That is, implement the method <code>track (int x)</code>, which is called when each number is generated, and the method <code>getRankOfNumber(int x)</code>, which returns the number of values less than or equal to <code>x</code>.</p>
|
|
|
|
|
|
|
|
<p><b>Note: </b>This problem is slightly different from the original one in the book.</p>
|
|
|
|
|
|
|
|
<p><strong>Example:</strong></p>
|
|
|
|
|
|
|
|
<pre>
|
|
|
|
<strong>Input:</strong>
|
|
|
|
["StreamRank", "getRankOfNumber", "track", "getRankOfNumber"]
|
|
|
|
[[], [1], [0], [0]]
|
|
|
|
<strong>Output:
|
|
|
|
</strong>[null,0,null,1]
|
|
|
|
</pre>
|
|
|
|
|
|
|
|
<p><strong>Note: </strong></p>
|
|
|
|
|
|
|
|
<ul>
|
|
|
|
<li><code>x <= 50000</code></li>
|
|
|
|
<li>The number of calls of both <code>track</code> and <code>getRankOfNumber</code> methods are less than or equal to 2000.</li>
|
|
|
|
</ul>
|
|
|