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)/三合一 [three-in-one-lcci].html
2022-03-29 12:43:11 +08:00

35 lines
1.1 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>三合一。描述如何只用一个数组来实现三个栈。</p>
<p>你应该实现<code>push(stackNum, value)</code><code>pop(stackNum)</code><code>isEmpty(stackNum)</code><code>peek(stackNum)</code>方法。<code>stackNum</code>表示栈下标,<code>value</code>表示压入的值。</p>
<p>构造函数会传入一个<code>stackSize</code>参数,代表每个栈的大小。</p>
<p><strong>示例1:</strong></p>
<pre>
<strong> 输入</strong>
["TripleInOne", "push", "push", "pop", "pop", "pop", "isEmpty"]
[[1], [0, 1], [0, 2], [0], [0], [0], [0]]
<strong> 输出</strong>
[null, null, null, 1, -1, -1, true]
<strong>说明</strong>:当栈为空时`pop, peek`返回-1当栈满时`push`不压入元素。
</pre>
<p><strong>示例2:</strong></p>
<pre>
<strong> 输入</strong>
["TripleInOne", "push", "push", "push", "pop", "pop", "pop", "peek"]
[[2], [0, 1], [0, 2], [0, 3], [0], [0], [0], [0]]
<strong> 输出</strong>
[null, null, null, null, 2, 1, -1, -1]
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>0 &lt;= stackNum &lt;= 2</code></li>
</ul>