[Leetcode] 121. Best Time to Buy and Sell Stock


問題のショートカット
class Solution:
    def maxProfit(self, prices: List[int]) -> int:
        minSoFar = prices[0]
        maxProfitSoFar = 0
        
        for price in prices:
            if minSoFar > price:
                minSoFar = price
                continue
            if maxProfitSoFar < price - minSoFar:
                maxProfitSoFar = price - minSoFar
        
        return maxProfitSoFar