Leetcode—2034.股票价格波动【中等】
2023每日刷题(五十二)
Leetcode—2034.股票价格波动
算法思想
实现代码
class StockPrice {
public:
int last = 0;
multiset<int> total;
unordered_map<int, int> m;
StockPrice() {
}
void update(int timestamp, int price) {
if(m.count(timestamp)) {
total.erase(total.find(m[timestamp]));
}
m[timestamp] = price;
total.insert(price);
last = max(last, timestamp);
}
int current() {
return m[last];
}
int maximum() {
return *total.rbegin();
}
int minimum() {
return *total.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();
*/
运行结果
之后我会持续更新,如果喜欢我的文章,请记得一键三连哦,点赞关注收藏,你的每一个赞每一份关注每一次收藏都将是我前进路上的无限动力 !!!↖(▔▽▔)↗感谢支持!