901. Online Stock Span
這個題目真的算是非常難,沒有寫過的話面試真的很難有機會寫出來。
class StockSpanner:
def __init__(self):
self.prices = []
def next(self, price: int) -> int:
count = 1
while self.prices and self.prices[-1][0] <= price:
prev = self.prices.pop()
count += prev[1]
self.prices.append([price, count])
return count
# Your StockSpanner object will be instantiated and called as such:
# obj = StockSpanner()
# param_1 = obj.next(price)