파비의 매일매일 공부기록

Today's Challenge 본문

Problem Solving/LeetCode

Today's Challenge

fabichoi 2022. 11. 9. 23:45

https://leetcode.com/problems/online-stock-span/

 

Online Stock Span - LeetCode

Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.

leetcode.com

스택을 써서 풀면 간단히 풀리는 문제~

class StockSpanner:

    def __init__(self):
        self.st = []

    def next(self, price: int) -> int:
        ans = 1
        while self.st and self.st[-1][0] <= price:
            ans += self.st.pop()[1]
        
        self.st.append([price, ans])
        return ans
반응형

'Problem Solving > LeetCode' 카테고리의 다른 글

Today's Challenge  (0) 2022.11.11
Today's Challenge  (0) 2022.11.10
Today's Challenge  (0) 2022.11.08
Today's Challenge  (0) 2022.11.07
Today's Challenge  (0) 2022.11.06
Comments