Leetcode 121. Best Time to Buy and Sell Stock

Mingyu Jeon·2020년 5월 7일
0
post-thumbnail

class Solution:
    def maxProfit(self, prices: List[int]) -> int:        
        minPrice = float(inf)
        profit = 0
        maxProfit = 0

        for i in range(len(prices)):
            minPrice = min(minPrice, prices[i])
            maxProfit = max(maxProfit, prices[i] - minPrice)

        return maxProfit

https://leetcode.com/problems/best-time-to-buy-and-sell-stock/

0개의 댓글