1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-11 02:58:13 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode-cn/problem (English)/三合一(English) [three-in-one-lcci].html

27 lines
1.4 KiB
HTML
Raw Normal View History

<p>Describe how you could use a single array to implement three stacks.</p>
<p>You&nbsp;should implement&nbsp;<code>push(stackNum, value)</code><code>pop(stackNum)</code><code>isEmpty(stackNum)</code><code>peek(stackNum)</code>&nbsp;methods.&nbsp;<code>stackNum<font face="sans-serif, Arial, Verdana, Trebuchet MS">&nbsp;</font></code><font face="sans-serif, Arial, Verdana, Trebuchet MS">is the index of the stack.&nbsp;</font><code>value</code>&nbsp;is the value that pushed to the stack.</p>
<p>The constructor requires a&nbsp;<code>stackSize</code>&nbsp;parameter, which represents the size of each stack.</p>
<p><strong>Example1:</strong></p>
<pre>
<strong> Input</strong>:
[&quot;TripleInOne&quot;, &quot;push&quot;, &quot;push&quot;, &quot;pop&quot;, &quot;pop&quot;, &quot;pop&quot;, &quot;isEmpty&quot;]
[[1], [0, 1], [0, 2], [0], [0], [0], [0]]
<strong> Output</strong>:
[null, null, null, 1, -1, -1, true]
<b>Explanation</b>: When the stack is empty, `pop, peek` return -1. When the stack is full, `push` does nothing.
</pre>
<p><strong>Example2:</strong></p>
<pre>
<strong> Input</strong>:
[&quot;TripleInOne&quot;, &quot;push&quot;, &quot;push&quot;, &quot;push&quot;, &quot;pop&quot;, &quot;pop&quot;, &quot;pop&quot;, &quot;peek&quot;]
[[2], [0, 1], [0, 2], [0, 3], [0], [0], [0], [0]]
<strong> Output</strong>:
[null, null, null, null, 2, 1, -1, -1]
</pre>