mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-01-10 18:48:13 +08:00
26 lines
971 B
HTML
26 lines
971 B
HTML
<p>Implement a MyQueue class which implements a queue using two stacks.</p>
|
|
|
|
|
|
|
|
|
|
|
|
<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> </p>
|
|
|
|
|
|
|
|
<p><b>Notes:</b></p>
|
|
|
|
|
|
|
|
<ul>
|
|
|
|
<li>You must use <i>only</i> standard operations of a stack -- which means only <code>push to top</code>, <code>peek/pop from top</code>, <code>size</code>, and <code>is empty</code> 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> </p>
|
|
|