gary@interview:~/interview/coding/901-online-stock….md$
$ cat ./coding/901-online-stock-span.md
[Coding]

901. Online Stock Span

────────────────────────────────────────────────────────────

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)
--tags#Stack#Monotonic
$ ls ./coding/ | grep -v 901-online-stock-span
265. Paint House II256. Paint House143. Reorder List1762. Buildings With an Ocean View
← cd ../codingcd ~