LC121 - Best Time to Buy and Sell Stock
Problem
Example
Solution
def maxProfit(self, prices: List[int]) -> int:
buyPrice = prices[0]
profit = 0
for price in prices[1:]:
if buyPrice > p:
buyPrice = p
profit = max(profit, p - buyPrice)
return profitLast updated