1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-11 02:58:13 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode-cn/problem (English)/数字流的秩(English) [rank-from-stream-lcci].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:&nbsp;</b>This problem is slightly different from the original one in the book.</p>
<p><strong>Example:</strong></p>
<pre>
<strong>Input:</strong>
[&quot;StreamRank&quot;, &quot;getRankOfNumber&quot;, &quot;track&quot;, &quot;getRankOfNumber&quot;]
[[], [1], [0], [0]]
<strong>Output:
</strong>[null,0,null,1]
</pre>
<p><strong>Note: </strong></p>
<ul>
<li><code>x &lt;= 50000</code></li>
<li>The number of calls of both&nbsp;<code>track</code>&nbsp;and&nbsp;<code>getRankOfNumber</code>&nbsp;methods are less than or equal to 2000.</li>
</ul>