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 (Chinese)/化栈为队 [implement-queue-using-stacks-lcci].html
2022-03-29 12:43:11 +08:00

1 line
794 B
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>实现一个MyQueue类该类用两个栈来实现一个队列。</p><br><p><strong>示例:</strong><pre>MyQueue queue = new MyQueue();<br><br>queue.push(1);<br>queue.push(2);<br>queue.peek(); // 返回 1<br>queue.pop(); // 返回 1<br>queue.empty(); // 返回 false</pre></p><br><p><strong>说明:</strong><br><ul><li>你只能使用标准的栈操作 -- 也就是只有 <code>push to top</code>, <code>peek/pop from top</code>, <code>size</code><code>is empty</code> 操作是合法的。</li><li>你所使用的语言也许不支持栈。你可以使用 list 或者 deque双端队列来模拟一个栈只要是标准的栈操作即可。</li><li>假设所有操作都是有效的 (例如,一个空的队列不会调用 pop 或者 peek 操作)。</li></ul></p>