标签:ret href pop amp 剑指offer instant led 队列 http
链接:https://leetcode-cn.com/problems/dui-lie-de-zui-da-zhi-lcof/
class MaxQueue {
public:
queue<int> q;
deque<int> d;
MaxQueue() {
}
int max_value() {
if (d.empty()) return -1;
return d.front();
}
void push_back(int value) {
while (!d.empty() && d.back() < value) d.pop_back();
d.push_back(value);
q.push(value);
}
int pop_front() {
if (q.empty()) return -1;
int ans = q.front();
if (ans == d.front()) d.pop_front();
q.pop();
return ans;
}
};
/**
* Your MaxQueue object will be instantiated and called as such:
* MaxQueue* obj = new MaxQueue();
* int param_1 = obj->max_value();
* obj->push_back(value);
* int param_3 = obj->pop_front();
*/
标签:ret href pop amp 剑指offer instant led 队列 http
原文地址:https://www.cnblogs.com/clown9804/p/12482769.html