class StockPrice {
private:unordered_map<int,int> mp; //存储日期及其对应的价格multiset<int> st; //存储所有价格int last_day; //最新一天
public:StockPrice() {this->last_day=0;}void update(int timestamp, int price) {if(mp.find(timestamp)!=mp.end())//如果能找到//删除再添加st.erase(st.find(mp[timestamp]));mp[timestamp]=price; //更新st.insert(price); this->last_day=this->last_day>timestamp?this->last_day:timestamp;//日期更新}int current() {return mp[this->last_day];}int maximum() {return *st.rbegin();//返回最大值}int minimum() {return *st.begin();//返回最小值}
};/*** Your StockPrice object will be instantiated and called as such:* StockPrice* obj = new StockPrice();* obj->update(timestamp,price);* int param_2 = obj->current();* int param_3 = obj->maximum();* int param_4 = obj->minimum();*/