原题
剑指offer 59-II.队列的最大值
/*
@v7fgg
执行用时:46 ms, 在所有 Java 提交中击败了14.83%的用户
内存消耗:48.1 MB, 在所有 Java 提交中击败了100.00%的用户
2020年7月16日 19:53
*/
class MaxQueue {
List<Integer> list;
public MaxQueue() {
list=new ArrayList<>();
}
public int max_value() {
if(list.isEmpty()){return -1;}
int ans=0;
for(int i=0;i<list.size();i++){
ans=Math.max(ans,list.get(i));
}
return ans;
}
public void push_back(int value) {
list.add(value);
}
public int pop_front() {
if(list.isEmpty()){return -1;}
else{
int a=list.get(0);
list.remove(0);
return a;
}
}
}
/**
* 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();
*/