mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-10-22 13:36:46 +08:00
update
This commit is contained in:
@@ -12,7 +12,7 @@
|
||||
"translatedContent": "<p>请你设计一个队列,支持在前,中,后三个位置的 <code>push</code> 和 <code>pop</code> 操作。</p>\n\n<p>请你完成 <code>FrontMiddleBack</code> 类:</p>\n\n<ul>\n\t<li><code>FrontMiddleBack()</code> 初始化队列。</li>\n\t<li><code>void pushFront(int val)</code> 将 <code>val</code> 添加到队列的 <strong>最前面</strong> 。</li>\n\t<li><code>void pushMiddle(int val)</code> 将 <code>val</code> 添加到队列的 <strong>正中间</strong> 。</li>\n\t<li><code>void pushBack(int val)</code> 将 <code>val</code> 添加到队里的 <strong>最后面</strong> 。</li>\n\t<li><code>int popFront()</code> 将 <strong>最前面</strong> 的元素从队列中删除并返回值,如果删除之前队列为空,那么返回 <code>-1</code> 。</li>\n\t<li><code>int popMiddle()</code> 将 <b>正中间</b> 的元素从队列中删除并返回值,如果删除之前队列为空,那么返回 <code>-1</code> 。</li>\n\t<li><code>int popBack()</code> 将 <strong>最后面</strong> 的元素从队列中删除并返回值,如果删除之前队列为空,那么返回 <code>-1</code> 。</li>\n</ul>\n\n<p>请注意当有 <strong>两个</strong> 中间位置的时候,选择靠前面的位置进行操作。比方说:</p>\n\n<ul>\n\t<li>将 <code>6</code> 添加到 <code>[1, 2, 3, 4, 5]</code> 的中间位置,结果数组为 <code>[1, 2, <strong>6</strong>, 3, 4, 5]</code> 。</li>\n\t<li>从 <code>[1, 2, <strong>3</strong>, 4, 5, 6]</code> 的中间位置弹出元素,返回 <code>3</code> ,数组变为 <code>[1, 2, 4, 5, 6]</code> 。</li>\n</ul>\n\n<p> </p>\n\n<p><strong>示例 1:</strong></p>\n\n<pre>\n<strong>输入:</strong>\n[\"FrontMiddleBackQueue\", \"pushFront\", \"pushBack\", \"pushMiddle\", \"pushMiddle\", \"popFront\", \"popMiddle\", \"popMiddle\", \"popBack\", \"popFront\"]\n[[], [1], [2], [3], [4], [], [], [], [], []]\n<strong>输出:</strong>\n[null, null, null, null, null, 1, 3, 4, 2, -1]\n\n<strong>解释:</strong>\nFrontMiddleBackQueue q = new FrontMiddleBackQueue();\nq.pushFront(1); // [<strong>1</strong>]\nq.pushBack(2); // [1, <strong>2</strong>]\nq.pushMiddle(3); // [1, <strong>3</strong>, 2]\nq.pushMiddle(4); // [1, <strong>4</strong>, 3, 2]\nq.popFront(); // 返回 1 -> [4, 3, 2]\nq.popMiddle(); // 返回 3 -> [4, 2]\nq.popMiddle(); // 返回 4 -> [2]\nq.popBack(); // 返回 2 -> []\nq.popFront(); // 返回 -1 -> [] (队列为空)\n</pre>\n\n<p> </p>\n\n<p><strong>提示:</strong></p>\n\n<ul>\n\t<li><code>1 <= val <= 10<sup>9</sup></code></li>\n\t<li>最多调用 <code>1000</code> 次 <code>pushFront</code>, <code>pushMiddle</code>, <code>pushBack</code>, <code>popFront</code>, <code>popMiddle</code> 和 <code>popBack</code> 。</li>\n</ul>\n",
|
||||
"isPaidOnly": false,
|
||||
"difficulty": "Medium",
|
||||
"likes": 18,
|
||||
"likes": 21,
|
||||
"dislikes": 0,
|
||||
"isLiked": null,
|
||||
"similarQuestions": "[]",
|
||||
@@ -161,7 +161,7 @@
|
||||
"__typename": "CodeSnippetNode"
|
||||
}
|
||||
],
|
||||
"stats": "{\"totalAccepted\": \"5.5K\", \"totalSubmission\": \"10.4K\", \"totalAcceptedRaw\": 5522, \"totalSubmissionRaw\": 10450, \"acRate\": \"52.8%\"}",
|
||||
"stats": "{\"totalAccepted\": \"5.7K\", \"totalSubmission\": \"10.7K\", \"totalAcceptedRaw\": 5660, \"totalSubmissionRaw\": 10728, \"acRate\": \"52.8%\"}",
|
||||
"hints": [
|
||||
"The constraints are low enough for a brute force, single array approach.",
|
||||
"For an O(1) per method approach, use 2 double-ended queues: one for the first half and one for the second half."
|
||||
|
Reference in New Issue
Block a user