본문 바로가기

자료구조와 알고리즘

121. Best Time to Buy and Sell Stock(주식을 사고팔기 가장 좋은 시점)

class Solution:
    def maxProfit(self, prices: List[int]) -> int:
        profit = 0
        min_price = sys.maxsize
        
        for price in prices:
            min_price = min(price, min_price)
            profit = max(profit, price - min_price)
            
        return profit