mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-01-10 18:48:13 +08:00
29 lines
1020 B
HTML
29 lines
1020 B
HTML
<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> 需要返回 -1</p>
|
||
|
||
<p><strong>示例 1:</strong></p>
|
||
|
||
<pre><strong>输入:</strong>
|
||
["MaxQueue","push_back","push_back","max_value","pop_front","max_value"]
|
||
[[],[1],[2],[],[],[]]
|
||
<strong>输出: </strong>[null,null,null,2,1,2]
|
||
</pre>
|
||
|
||
<p><strong>示例 2:</strong></p>
|
||
|
||
<pre><strong>输入:</strong>
|
||
["MaxQueue","pop_front","max_value"]
|
||
[[],[],[]]
|
||
<strong>输出: </strong>[null,-1,-1]
|
||
</pre>
|
||
|
||
<p> </p>
|
||
|
||
<p><strong>限制:</strong></p>
|
||
|
||
<ul>
|
||
<li><code>1 <= push_back,pop_front,max_value的总操作数 <= 10000</code></li>
|
||
<li><code>1 <= value <= 10^5</code></li>
|
||
</ul>
|