1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-09-09 01:11:42 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
This commit is contained in:
2022-05-02 23:44:12 +08:00
parent 7ea03594b3
commit 2a71c78585
4790 changed files with 11696 additions and 10944 deletions

View File

@@ -12,7 +12,7 @@
"translatedContent": "<p>我们把无限数量 &infin; 的栈排成一行,按从左到右的次序从 0 开始编号。每个栈的的最大容量&nbsp;<code>capacity</code> 都相同。</p>\n\n<p>实现一个叫「餐盘」的类&nbsp;<code>DinnerPlates</code></p>\n\n<ul>\n\t<li><code>DinnerPlates(int capacity)</code>&nbsp;- 给出栈的最大容量&nbsp;<code>capacity</code>。</li>\n\t<li><code>void push(int val)</code>&nbsp;- 将给出的正整数&nbsp;<code>val</code>&nbsp;推入&nbsp;<strong>从左往右第一个&nbsp;</strong>没有满的栈。</li>\n\t<li><code>int pop()</code>&nbsp;- 返回&nbsp;<strong>从右往左第一个&nbsp;</strong>非空栈顶部的值,并将其从栈中删除;如果所有的栈都是空的,请返回&nbsp;<code>-1</code>。</li>\n\t<li><code>int popAtStack(int index)</code>&nbsp;- 返回编号&nbsp;<code>index</code>&nbsp;的栈顶部的值,并将其从栈中删除;如果编号&nbsp;<code>index</code>&nbsp;的栈是空的,请返回 <code>-1</code>。</li>\n</ul>\n\n<p>&nbsp;</p>\n\n<p><strong>示例:</strong></p>\n\n<pre><strong>输入: </strong>\n[&quot;DinnerPlates&quot;,&quot;push&quot;,&quot;push&quot;,&quot;push&quot;,&quot;push&quot;,&quot;push&quot;,&quot;popAtStack&quot;,&quot;push&quot;,&quot;push&quot;,&quot;popAtStack&quot;,&quot;popAtStack&quot;,&quot;pop&quot;,&quot;pop&quot;,&quot;pop&quot;,&quot;pop&quot;,&quot;pop&quot;]\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 &nbsp;4\n&nbsp; 1 &nbsp;3 &nbsp;5\n ﹈ ﹈ ﹈\nD.popAtStack(0); // 返回 2。栈的现状为 &nbsp;4\n &nbsp; 1 &nbsp;3 &nbsp;5\n ﹈ ﹈ ﹈\nD.push(20); // 栈的现状为: 20 4\n&nbsp; 1 &nbsp;3 &nbsp;5\n ﹈ ﹈ ﹈\nD.push(21); // 栈的现状为: 20 4 21\n&nbsp; 1 &nbsp;3 &nbsp;5\n ﹈ ﹈ ﹈\nD.popAtStack(0); // 返回 20。栈的现状为 4 21\n &nbsp; 1 &nbsp;3 &nbsp;5\n ﹈ ﹈ ﹈\nD.popAtStack(2); // 返回 21。栈的现状为 4\n &nbsp; 1 &nbsp;3 &nbsp;5\n ﹈ ﹈ ﹈ \nD.pop() // 返回 5。栈的现状为 4\n &nbsp; 1 &nbsp;3 \n ﹈ ﹈ \nD.pop() // 返回 4。栈的现状为 1 3 \n ﹈ ﹈ \nD.pop() // 返回 3。栈的现状为 1 \n ﹈ \nD.pop() // 返回 1。现在没有栈。\nD.pop() // 返回 -1。仍然没有栈。\n</pre>\n\n<p>&nbsp;</p>\n\n<p><strong>提示:</strong></p>\n\n<ul>\n\t<li><code>1 &lt;= capacity&nbsp;&lt;= 20000</code></li>\n\t<li><code>1 &lt;= val&nbsp;&lt;= 20000</code></li>\n\t<li><code>0 &lt;= index&nbsp;&lt;= 100000</code></li>\n\t<li>最多会对&nbsp;<code>push</code><code>pop</code>,和&nbsp;<code>popAtStack</code>&nbsp;进行 <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."