1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-11 19:18:14 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/算法题(国内版)/problem (Chinese)/队列的最大值 [dui-lie-de-zui-da-zhi-lcof].html

29 lines
1020 B
HTML
Raw Normal View History

2022-03-27 20:38:29 +08:00
<p>请定义一个队列并实现函数 <code>max_value</code> 得到队列里的最大值,要求函数<code>max_value</code><code>push_back</code><code>pop_front</code><strong>均摊</strong>时间复杂度都是O(1)。</p>
<p>若队列为空,<code>pop_front</code><code>max_value</code>&nbsp;需要返回 -1</p>
<p><strong>示例 1</strong></p>
<pre><strong>输入:</strong>
[&quot;MaxQueue&quot;,&quot;push_back&quot;,&quot;push_back&quot;,&quot;max_value&quot;,&quot;pop_front&quot;,&quot;max_value&quot;]
[[],[1],[2],[],[],[]]
<strong>输出:&nbsp;</strong>[null,null,null,2,1,2]
</pre>
<p><strong>示例 2</strong></p>
<pre><strong>输入:</strong>
[&quot;MaxQueue&quot;,&quot;pop_front&quot;,&quot;max_value&quot;]
[[],[],[]]
<strong>输出:&nbsp;</strong>[null,-1,-1]
</pre>
<p>&nbsp;</p>
<p><strong>限制:</strong></p>
<ul>
<li><code>1 &lt;= push_back,pop_front,max_value的总操作数&nbsp;&lt;= 10000</code></li>
<li><code>1 &lt;= value &lt;= 10^5</code></li>
</ul>