Skip to content

Commit 103731f

Browse files
committed
first version: error
1 parent ff4e1fe commit 103731f

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#ifdef _WIN32
2+
#include "_[1,2]toVector.h"
3+
#endif
4+
5+
class StockPrice {
6+
private:
7+
unordered_map<int, int> ma;
8+
multiset<int> se;
9+
int Mtime;
10+
public:
11+
StockPrice() {
12+
Mtime = 0;
13+
}
14+
15+
void update(int timestamp, int price) {
16+
if (ma.count(timestamp)) {
17+
se.erase(ma[timestamp]);
18+
}
19+
ma[timestamp] = price;
20+
se.insert(price);
21+
Mtime = max(Mtime, timestamp);
22+
}
23+
24+
int current() {
25+
return ma[Mtime];
26+
}
27+
28+
int maximum() {
29+
return ma[*se.end()];
30+
}
31+
32+
int minimum() {
33+
return ma[*se.begin()];
34+
}
35+
};
36+
37+
/**
38+
* Your StockPrice object will be instantiated and called as such:
39+
* StockPrice* obj = new StockPrice();
40+
* obj->update(timestamp,price);
41+
* int param_2 = obj->current();
42+
* int param_3 = obj->maximum();
43+
* int param_4 = obj->minimum();
44+
*/

0 commit comments

Comments
 (0)