mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-09-09 01:11:42 +08:00
update
This commit is contained in:
@@ -12,7 +12,7 @@
|
||||
"translatedContent": "<p>我们把无限数量 ∞ 的栈排成一行,按从左到右的次序从 0 开始编号。每个栈的的最大容量 <code>capacity</code> 都相同。</p>\n\n<p>实现一个叫「餐盘」的类 <code>DinnerPlates</code>:</p>\n\n<ul>\n\t<li><code>DinnerPlates(int capacity)</code> - 给出栈的最大容量 <code>capacity</code>。</li>\n\t<li><code>void push(int val)</code> - 将给出的正整数 <code>val</code> 推入 <strong>从左往右第一个 </strong>没有满的栈。</li>\n\t<li><code>int pop()</code> - 返回 <strong>从右往左第一个 </strong>非空栈顶部的值,并将其从栈中删除;如果所有的栈都是空的,请返回 <code>-1</code>。</li>\n\t<li><code>int popAtStack(int index)</code> - 返回编号 <code>index</code> 的栈顶部的值,并将其从栈中删除;如果编号 <code>index</code> 的栈是空的,请返回 <code>-1</code>。</li>\n</ul>\n\n<p> </p>\n\n<p><strong>示例:</strong></p>\n\n<pre><strong>输入: </strong>\n["DinnerPlates","push","push","push","push","push","popAtStack","push","push","popAtStack","popAtStack","pop","pop","pop","pop","pop"]\n[[2],[1],[2],[3],[4],[5],[0],[20],[21],[0],[2],[],[],[],[],[]]\n<strong>输出:</strong>\n[null,null,null,null,null,null,2,null,null,20,21,5,4,3,1,-1]\n\n<strong>解释:</strong>\nDinnerPlates D = DinnerPlates(2); // 初始化,栈最大容量 capacity = 2\nD.push(1);\nD.push(2);\nD.push(3);\nD.push(4);\nD.push(5); // 栈的现状为: 2 4\n 1 3 5\n ﹈ ﹈ ﹈\nD.popAtStack(0); // 返回 2。栈的现状为: 4\n 1 3 5\n ﹈ ﹈ ﹈\nD.push(20); // 栈的现状为: 20 4\n 1 3 5\n ﹈ ﹈ ﹈\nD.push(21); // 栈的现状为: 20 4 21\n 1 3 5\n ﹈ ﹈ ﹈\nD.popAtStack(0); // 返回 20。栈的现状为: 4 21\n 1 3 5\n ﹈ ﹈ ﹈\nD.popAtStack(2); // 返回 21。栈的现状为: 4\n 1 3 5\n ﹈ ﹈ ﹈ \nD.pop() // 返回 5。栈的现状为: 4\n 1 3 \n ﹈ ﹈ \nD.pop() // 返回 4。栈的现状为: 1 3 \n ﹈ ﹈ \nD.pop() // 返回 3。栈的现状为: 1 \n ﹈ \nD.pop() // 返回 1。现在没有栈。\nD.pop() // 返回 -1。仍然没有栈。\n</pre>\n\n<p> </p>\n\n<p><strong>提示:</strong></p>\n\n<ul>\n\t<li><code>1 <= capacity <= 20000</code></li>\n\t<li><code>1 <= val <= 20000</code></li>\n\t<li><code>0 <= index <= 100000</code></li>\n\t<li>最多会对 <code>push</code>,<code>pop</code>,和 <code>popAtStack</code> 进行 <code>200000</code> 次调用。</li>\n</ul>\n",
|
||||
"isPaidOnly": false,
|
||||
"difficulty": "Hard",
|
||||
"likes": 33,
|
||||
"likes": 35,
|
||||
"dislikes": 0,
|
||||
"isLiked": null,
|
||||
"similarQuestions": "[]",
|
||||
@@ -155,7 +155,7 @@
|
||||
"__typename": "CodeSnippetNode"
|
||||
}
|
||||
],
|
||||
"stats": "{\"totalAccepted\": \"2.8K\", \"totalSubmission\": \"10.6K\", \"totalAcceptedRaw\": 2835, \"totalSubmissionRaw\": 10632, \"acRate\": \"26.7%\"}",
|
||||
"stats": "{\"totalAccepted\": \"2.9K\", \"totalSubmission\": \"10.9K\", \"totalAcceptedRaw\": 2904, \"totalSubmissionRaw\": 10882, \"acRate\": \"26.7%\"}",
|
||||
"hints": [
|
||||
"Use a data structure to save the plate status. You may need to operate the exact index. Maintain the leftmost vacant stack and the rightmost non-empty stack.",
|
||||
"Use a list of stack to store the plate status. Use heap to maintain the leftmost and rightmost valid stack."
|
||||
|
Reference in New Issue
Block a user