1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-10 18:48:13 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode-cn/problem (Chinese)/数据流中的中位数 [shu-ju-liu-zhong-de-zhong-wei-shu-lcof].html

41 lines
1.4 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<p><strong>中位数&nbsp;</strong>是有序整数列表中的中间值。如果列表的大小是偶数,则没有中间值,中位数是两个中间值的平均值。</p>
<p>例如,<br />
<code>[2,3,4]</code> 的中位数是 <code>3</code><br />
<code>[2,3]</code> 的中位数是 <code>(2 + 3) / 2 = 2.5</code><br />
设计一个支持以下两种操作的数据结构:</p>
<ul>
<li><code>void addNum(int num)</code> - 从数据流中添加一个整数到数据结构中。</li>
<li><code>double findMedian()</code> - 返回目前所有元素的中位数。</li>
</ul>
<p><strong>示例 1</strong></p>
<pre>
<strong>输入:
</strong>["MedianFinder","addNum","addNum","findMedian","addNum","findMedian"]
[[],[1],[2],[],[3],[]]
<strong>输出:</strong>[null,null,null,1.50000,null,2.00000]
</pre>
<p><strong>示例 2</strong></p>
<pre>
<strong>输入:
</strong>["MedianFinder","addNum","findMedian","addNum","findMedian"]
[[],[2],[],[3],[]]
<strong>输出:</strong>[null,null,2.00000,null,2.50000]</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li>最多会对&nbsp;<code>addNum、findMedian</code> 进行&nbsp;<code>50000</code>&nbsp;次调用。</li>
</ul>
<p>注意:本题与主站 295 题相同:<a href="https://leetcode-cn.com/problems/find-median-from-data-stream/">https://leetcode-cn.com/problems/find-median-from-data-stream/</a></p>
<p>&nbsp;</p>