-
Notifications
You must be signed in to change notification settings - Fork 0
/
2034.py
47 lines (38 loc) · 1.21 KB
/
2034.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
from sortedcontainers import SortedList
class StockPrice(object):
def __init__(self):
self.data_flow = {}
self.save_date = SortedList()
self.current_time = None
def update(self, timestamp, price):
"""
:type timestamp: int
:type price: int
:rtype: None
"""
if self.current_time == None or timestamp > self.current_time or self.data_flow.get(timestamp,False) ==False :
self.save_date.add(price)
else:
for i in range(len(self.save_date)):
if self.save_date[i] == self.data_flow[timestamp]:
self.save_date.discard(self.data_flow[timestamp])
self.save_date.add(price)
break
self.data_flow[timestamp] = price
if self.current_time == None or self.current_time <timestamp:
self.current_time = timestamp
def current(self):
"""
:rtype: int
"""
return self.data_flow[self.current_time]
def maximum(self):
"""
:rtype: int
"""
return self.save_date[-1]
def minimum(self):
"""
:rtype: int
"""
return self.save_date[0]