mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-10-22 05:26:46 +08:00
update
This commit is contained in:
@@ -12,7 +12,7 @@
|
||||
"translatedContent": "<p>给你两个整数 <code>m</code> 和 <code>k</code> ,以及数据流形式的若干整数。你需要实现一个数据结构,计算这个数据流的 <b>MK 平均值</b> 。</p>\n\n<p><strong>MK 平均值</strong> 按照如下步骤计算:</p>\n\n<ol>\n\t<li>如果数据流中的整数少于 <code>m</code> 个,<strong>MK 平均值</strong> 为 <code>-1</code> ,否则将数据流中最后 <code>m</code> 个元素拷贝到一个独立的容器中。</li>\n\t<li>从这个容器中删除最小的 <code>k</code> 个数和最大的 <code>k</code> 个数。</li>\n\t<li>计算剩余元素的平均值,并 <strong>向下取整到最近的整数</strong> 。</li>\n</ol>\n\n<p>请你实现 <code>MKAverage</code> 类:</p>\n\n<ul>\n\t<li><code>MKAverage(int m, int k)</code> 用一个空的数据流和两个整数 <code>m</code> 和 <code>k</code> 初始化 <strong>MKAverage</strong> 对象。</li>\n\t<li><code>void addElement(int num)</code> 往数据流中插入一个新的元素 <code>num</code> 。</li>\n\t<li><code>int calculateMKAverage()</code> 对当前的数据流计算并返回 <strong>MK 平均数</strong> ,结果需 <strong>向下取整到最近的整数</strong> 。</li>\n</ul>\n\n<p> </p>\n\n<p><strong>示例 1:</strong></p>\n\n<pre>\n<strong>输入:</strong>\n[\"MKAverage\", \"addElement\", \"addElement\", \"calculateMKAverage\", \"addElement\", \"calculateMKAverage\", \"addElement\", \"addElement\", \"addElement\", \"calculateMKAverage\"]\n[[3, 1], [3], [1], [], [10], [], [5], [5], [5], []]\n<strong>输出:</strong>\n[null, null, null, -1, null, 3, null, null, null, 5]\n\n<strong>解释:</strong>\nMKAverage obj = new MKAverage(3, 1); \nobj.addElement(3); // 当前元素为 [3]\nobj.addElement(1); // 当前元素为 [3,1]\nobj.calculateMKAverage(); // 返回 -1 ,因为 m = 3 ,但数据流中只有 2 个元素\nobj.addElement(10); // 当前元素为 [3,1,10]\nobj.calculateMKAverage(); // 最后 3 个元素为 [3,1,10]\n // 删除最小以及最大的 1 个元素后,容器为 <code>[3]\n // [3] 的平均值等于 3/1 = 3 ,故返回 3\nobj.addElement(5); // 当前元素为 [3,1,10,5]\nobj.addElement(5); // 当前元素为 [3,1,10,5,5]\nobj.addElement(5); // 当前元素为 [3,1,10,5,5,5]\nobj.calculateMKAverage(); // 最后 3 个元素为 [5,5,5]\n // </code>删除最小以及最大的 1 个元素后,容器为 <code>[5]<code>\n // </code>[5] 的平均值等于 5/1 = 5 ,故返回 5<code>\n</code></code></pre>\n\n<p> </p>\n\n<p><strong>提示:</strong></p>\n\n<ul>\n\t<li><code>3 <= m <= 10<sup>5</sup></code></li>\n\t<li><code>1 <= k*2 < m</code></li>\n\t<li><code>1 <= num <= 10<sup>5</sup></code></li>\n\t<li><code>addElement</code> 与 <code>calculateMKAverage</code> 总操作次数不超过 <code>10<sup>5</sup></code> 次。</li>\n</ul>\n",
|
||||
"isPaidOnly": false,
|
||||
"difficulty": "Hard",
|
||||
"likes": 28,
|
||||
"likes": 29,
|
||||
"dislikes": 0,
|
||||
"isLiked": null,
|
||||
"similarQuestions": "[]",
|
||||
@@ -155,7 +155,7 @@
|
||||
"__typename": "CodeSnippetNode"
|
||||
}
|
||||
],
|
||||
"stats": "{\"totalAccepted\": \"2.9K\", \"totalSubmission\": \"10K\", \"totalAcceptedRaw\": 2869, \"totalSubmissionRaw\": 9973, \"acRate\": \"28.8%\"}",
|
||||
"stats": "{\"totalAccepted\": \"2.9K\", \"totalSubmission\": \"10.1K\", \"totalAcceptedRaw\": 2919, \"totalSubmissionRaw\": 10087, \"acRate\": \"28.9%\"}",
|
||||
"hints": [
|
||||
"At each query, try to save and update the sum of the elements needed to calculate MKAverage.",
|
||||
"You can use BSTs for fast insertion and deletion of the elements."
|
||||
|
Reference in New Issue
Block a user