【Python】详解 bisect 模块_闻韶-CSDN博客
5896. 股票价格波动
class StockPrice(object):
def __init__(self):
self.cur=[0,0]
self.price=[]
self.time={}
def update(self, timestamp, price):
"""
:type timestamp: int
:type price: int
:rtype: None
"""
#如果时间戳大于当前时间
if timestamp>=self.cur[0]:
self.cur=[timestamp, price]
#把price插入到price列表里
#如果timestamp以前出现过
if timestamp in self.time:
#删掉这个时间戳下以前的价格
self.price.remove(self.time[timestamp])
bisect.insort(self.price,price)
self.time[timestamp]=price
def current(self):
"""
:rtype: int
"""
return self.cur[1]
def maximum(self):
"""
:rtype: int
"""
return self.price[-1]
def minimum(self):
"""
:rtype: int
"""
return self.price[0]
# Your StockPrice object will be instantiated and called as such:
# obj = StockPrice()
# obj.update(timestamp,price)
# param_2 = obj.current()
# param_3 = obj.maximum()
# param_4 = obj.minimum()



