Created
November 9, 2022 01:02
-
-
Save EfrainReyes/12a061ce9c9f74e80f0b6db12341f79d to your computer and use it in GitHub Desktop.
901. Online Stock Span
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class StockSpanner: | |
def __init__(self): | |
self.span_stack = [] | |
def next(self, price: int) -> int: | |
span = 1 | |
while self.span_stack and price >= self.span_stack[-1][0]: | |
span += self.span_stack.pop()[1] | |
self.span_stack.append((price, span)) | |
return span |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment