1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-10 18:48:13 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode-cn/problem (Chinese)/堆盘子 [stack-of-plates-lcci].html
2022-03-29 12:43:11 +08:00

22 lines
1.4 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<p>堆盘子。设想有一堆盘子,堆太高可能会倒下来。因此,在现实生活中,盘子堆到一定高度时,我们就会另外堆一堆盘子。请实现数据结构<code>SetOfStacks</code>,模拟这种行为。<code>SetOfStacks</code>应该由多个栈组成,并且在前一个栈填满时新建一个栈。此外,<code>SetOfStacks.push()</code><code>SetOfStacks.pop()</code>应该与普通栈的操作方法相同也就是说pop()返回的值,应该跟只有一个栈时的情况一样)。 进阶:实现一个<code>popAt(int index)</code>方法根据指定的子栈执行pop操作。</p>
<p>当某个栈为空时,应当删除该栈。当栈中没有元素或不存在该栈时,<code>pop</code><code>popAt</code>&nbsp;应返回 -1.</p>
<p><strong>示例1:</strong></p>
<pre><strong> 输入</strong>
[&quot;StackOfPlates&quot;, &quot;push&quot;, &quot;push&quot;, &quot;popAt&quot;, &quot;pop&quot;, &quot;pop&quot;]
[[1], [1], [2], [1], [], []]
<strong> 输出</strong>
[null, null, null, 2, 1, -1]
</pre>
<p><strong>示例2:</strong></p>
<pre><strong> 输入</strong>
[&quot;StackOfPlates&quot;, &quot;push&quot;, &quot;push&quot;, &quot;push&quot;, &quot;popAt&quot;, &quot;popAt&quot;, &quot;popAt&quot;]
[[2], [1], [2], [3], [0], [0], [0]]
<strong> 输出</strong>
[null, null, null, null, 2, 1, 3]
</pre>