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 (English)/化栈为队(English) [implement-queue-using-stacks-lcci].html

26 lines
971 B
HTML

<p>Implement a MyQueue class which implements a queue using two stacks.</p>
&nbsp;
<p><strong>Example: </strong></p>
<pre>
MyQueue queue = new MyQueue();
queue.push(1);
queue.push(2);
queue.peek(); // return 1
queue.pop(); // return 1
queue.empty(); // return false</pre>
<p>&nbsp;</p>
<p><b>Notes:</b></p>
<ul>
<li>You must use&nbsp;<i>only</i>&nbsp;standard operations of a stack -- which means only&nbsp;<code>push to top</code>,&nbsp;<code>peek/pop from top</code>,&nbsp;<code>size</code>, and&nbsp;<code>is empty</code>&nbsp;operations are valid.</li>
<li>Depending on your language, stack may not be supported natively. You may simulate a stack by using a list or deque (double-ended queue), as long as you use only standard operations of a stack.</li>
<li>You may assume that all operations are valid (for example, no pop or peek operations will be called on an empty queue).</li>
</ul>
<p>&nbsp;</p>