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 (Chinese)/队列的最大值 [dui-lie-de-zui-da-zhi-lcof].html
2022-03-29 12:43:11 +08:00

29 lines
1020 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>请定义一个队列并实现函数 <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>