best-time-to-buy-and-sell-stock
class Solution:
def maxProfit(self, prices: List[int]) -> int:
if not prices:
return 0
min_val = prices[0]
max_profit = 0
for price in prices:
if price < min_val:
min_val = price
profit = price - min_val
if profit > max_profit:
max_profit = profit
return max_profit
Comments
Post a Comment