# 59-II.队列的最大值

### 一、 题目

请定义一个队列并实现函数 max\_value 得到队列里的最大值，要求函数max\_value、push\_back 和 pop\_front 的均摊时间复杂度都是O(1)。

若队列为空，pop\_front 和 max\_value 需要返回 -1

示例 1：

输入:

\["MaxQueue","push\_back","push\_back","max\_value","pop\_front","max\_value"]

\[\[],\[1],\[2],\[],\[],\[]]

输出: \[null,null,null,2,1,2]

示例 2：

输入:

\["MaxQueue","pop\_front","max\_value"]

\[\[],\[],\[]]

输出: \[null,-1,-1]   限制：

1 <= push\_back,pop\_front,max\_value的总操作数 <= 10000

1 <= value <= 10^5

来源：力扣（LeetCode）

链接：<https://leetcode-cn.com/problems/dui-lie-de-zui-da-zhi-lcof>

著作权归领扣网络所有。商业转载请联系官方授权，非商业转载请注明出处。

### 二、 解法

实现一个优先队列么


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://ryukiedev.gitbook.io/wiki/shu-ju-jie-gou-yu-suan-fa/jian-zhi-offerswift/59ii.-dui-lie-de-zui-da-zhi.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
