mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-09-13 19:31:42 +08:00
add leetcode problem-cn part6
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
<p>中位数是有序列表中间的数。如果列表长度是偶数,中位数则是中间两个数的平均值。</p>
|
||||
|
||||
<p>例如,</p>
|
||||
|
||||
<p>[2,3,4] 的中位数是 3</p>
|
||||
|
||||
<p>[2,3] 的中位数是 (2 + 3) / 2 = 2.5</p>
|
||||
|
||||
<p>设计一个支持以下两种操作的数据结构:</p>
|
||||
|
||||
<ul>
|
||||
<li>void addNum(int num) - 从数据流中添加一个整数到数据结构中。</li>
|
||||
<li>double findMedian() - 返回目前所有元素的中位数。</li>
|
||||
</ul>
|
||||
|
||||
<p><strong>示例:</strong></p>
|
||||
|
||||
<pre>addNum(1)
|
||||
addNum(2)
|
||||
findMedian() -> 1.5
|
||||
addNum(3)
|
||||
findMedian() -> 2</pre>
|
||||
|
||||
<p><strong>进阶:</strong></p>
|
||||
|
||||
<ol>
|
||||
<li>如果数据流中所有整数都在 0 到 100 范围内,你将如何优化你的算法?</li>
|
||||
<li>如果数据流中 99% 的整数都在 0 到 100 范围内,你将如何优化你的算法?</li>
|
||||
</ol>
|
Reference in New Issue
Block a user