本文主要是介绍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();*/
运行结果
之后我会持续更新,如果喜欢我的文章,请记得一键三连哦,点赞关注收藏,你的每一个赞每一份关注每一次收藏都将是我前进路上的无限动力 !!!↖(▔▽▔)↗感谢支持!
这篇关于Leetcode—2034.股票价格波动【中等】的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!