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)/用两个栈实现队列 [yong-liang-ge-zhan-shi-xian-dui-lie-lcof].html

27 lines
1023 B
HTML
Raw Normal View History

2022-03-27 20:38:29 +08:00
<p>用两个栈实现一个队列。队列的声明如下,请实现它的两个函数 <code>appendTail</code><code>deleteHead</code> ,分别完成在队列尾部插入整数和在队列头部删除整数的功能。(若队列中没有元素,<code>deleteHead</code>&nbsp;操作返回 -1 )</p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<pre><strong>输入:</strong>
[&quot;CQueue&quot;,&quot;appendTail&quot;,&quot;deleteHead&quot;,&quot;deleteHead&quot;]
[[],[3],[],[]]
<strong>输出:</strong>[null,null,3,-1]
</pre>
<p><strong>示例 2</strong></p>
<pre><strong>输入:</strong>
[&quot;CQueue&quot;,&quot;deleteHead&quot;,&quot;appendTail&quot;,&quot;appendTail&quot;,&quot;deleteHead&quot;,&quot;deleteHead&quot;]
[[],[],[5],[2],[],[]]
<strong>输出:</strong>[null,-1,null,null,5,2]
</pre>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= values &lt;= 10000</code></li>
<li><code>最多会对&nbsp;appendTail、deleteHead 进行&nbsp;10000&nbsp;次调用</code></li>
</ul>